title: Problems with additional libraries in creating a DLL through Cython
body: <p>I try to create a DLL out of my Python program. Therefore I used Cython to convert the Python program into a C program and simply followed the steps mentioned in the answer for this <a href="https://stackoverflow.com/questions/18515275/can-cython-code-be-compiled-to-a-dll-so-c-application-can-call-it">question</a> to call my methods. However, this works fine for simple methods where no additional libraries are required but not when I want to use my Logistic Regression.</p>
  <p>I created beforehand a json file out of my trained ML algorithm, which I afterwards loaded in my predict.pyx file with sklearn_json. In my predict.pyx file are the following methods included:</p>
  <pre><code>import sklearn_json as skljson
  
  # predict for the incoming values
  cdef public int predict(double val_one, double val_two):
  
      deserialized_model = skljson.from_json('json_model')
      prediction = deserialized_model.predict([[val_one, val_two]])
  
      return int(prediction[0])
  
  # say hello and return an integer
  cdef public int sayHello():
      print(&quot;Hello, I am your python program.\n&quot;)
      cdef int a = 5
      return a
  </code></pre>
  <p>Afterwards I created through the command line the C files with:</p>
  <pre><code>Cython predict.pyx
  </code></pre>
  <p>Then I built two classes similar to cyfun_dll.c and cyfun_dll.h from the answer of this <a href="https://stackoverflow.com/questions/18515275/can-cython-code-be-compiled-to-a-dll-so-c-application-can-call-it">post</a>.</p>
  <p>and I ran the following commands in the command line:</p>
  <pre><code>gcc -c -DBUILD_DLL predict.c  -IC:/Users/Hannah/Anaconda3/include
  gcc -c -DBUILD_DLL predict_dll.c  -IC:/Users/Hannah/Anaconda3/include
  gcc -shared -o hello.dll predict.o predict_dll.o -LC:/Users/Hannah/Anaconda3/libs -lpython38
  </code></pre>
  <p>to create my DLL.</p>
  <p>Furthermore, I also have a dllhandler.c to call the methods from my created DLL. However, as soon as I execute dllhandler.exe I got the following error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;predict.pyx&quot;, line 4, in init predict
      import sklearn_json as skljson
  ModuleNotFoundError: No module named 'sklearn_json'
  Error occurred when loading library: 1114
  </code></pre>
  <p>I could solve this error through copying the folder &quot;sklearn_json&quot; from the site-packages from Anaconda into the folder from my program. However, afterwards I got the following error:</p>
  <pre><code> File &quot;predict.pyx&quot;, line 4, in init predict
      import sklearn_json as skljson
    File &quot;C:\Users\Hannah\Documents\VS Code - Cython V3\sklearn_json\__init__.py&quot;, line 1, in &lt;module&gt;
      from sklearn_json import classification as clf
    File &quot;C:\Users\Hannah\Documents\VS Code - Cython V3\sklearn_json\classification.py&quot;, line 1, in &lt;module&gt;
      import numpy as np
  ModuleNotFoundError: No module named 'numpy'
  Error occurred when loading library: 1114
  </code></pre>
  <p>This problem could be solved through copying the numpy directory from the Cython folder into the directory of my program. However, the same problem arrose with scipy, but this couldn't be solved through copying the scipy folder. I got the following error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;predict.pyx&quot;, line 4, in init predict
      import sklearn_json as skljson
    File &quot;C:\Users\Hannah\Documents\VS Code - Cython V3\sklearn_json\__init__.py&quot;, line 1, in &lt;module&gt;
      from sklearn_json import classification as clf
    File &quot;C:\Users\Hannah\Documents\VS Code - Cython V3\sklearn_json\classification.py&quot;, line 2, in &lt;module&gt;
      import scipy as sp
    File &quot;C:\Users\Hannah\Documents\VS Code - Cython V3\scipy\__init__.py&quot;, line 61, in &lt;module&gt;
      from numpy import show_config as show_numpy_config
  ImportError: cannot import name 'show_config' from 'numpy' (unknown location)
  </code></pre>
  <p>I don't think that it should be necessary to change the code in the files. Additionally, I think that there must be a much better solution than copying the folders.</p>
  <p>Does anybody have experience with Cython and additional libraries? How could I solve this error? Is there a better way to solve my problems without copying the folders? Or is there a way to use a ML model in json format to call and use for predictions in C directly. Thanks for any addvice.</p>
  <p><strong>EDIT:</strong>
  As suggested in the comments I looked at my sys.path which looks the following:</p>
  <pre><code>['C:\\Users\\Hannah\\Documents\\VS Code - Cython V3', 'C:\\Users\\Hannah\\Anaconda3\\python38.zip', 'C:\\Users\\Hannah\\Anaconda3\\DLLs', 'C:\\Users\\Hannah\\Anaconda3\\lib', 'C:\\Users\\Hannah\\Anaconda3', 'C:\\Users\\Hannah\\Anaconda3\\lib\\site-packages', 'C:\\Users\\Hannah\\Anaconda3\\lib\\site-packages\\win32', 'C:\\Users\\Hannah\\Anaconda3\\lib\\site-packages\\win32\\lib', 'C:\\Users\\Hannah\\Anaconda3\\lib\\site-packages\\Pythonwin']
  </code></pre>
  <p>This means my program should know where to find the packages like numpy, sklearn_json etc as it knows the path to the site-packages - but it doesn't work.</p>
  <p>Maybe it is also good to know (as I saw it in the linked post in the comment) that I added python38.dll and python38.zip also in the same folder as my programs to make the python file callable from my DLL.</p>
  <p><strong>Second Edit:</strong>
  Is there any possibility, that the problem lies in the settings.json file in Visual Studio Code? Maybe there the path points to the wrong directory and it is therefore required to copy all required libraries? I do not know which settings should be changed there, has anybody a suggestion?</p>