Question

I am used with compiling self-made python extensions under Linux using Cython. On Linux, I use distutils to produce a "myext.so", that I can then simply add to my PYTHONPATH and get the import myext python call available.

Now, I am trying to get it working under Windows 7 (using Cython 0.18). I successfully ran distutils such that I now get a myext.pyd file. But it seems (http://docs.python.org/2/faq/windows.html#is-a-pyd-file-the-same-as-a-dll) that adding the path to "myext.pyd" is not enough under windows. What should the "myext.py" look like or, in other words, what is the procedure to get my extension available in my Python (2.7) installation.

Note : After having added the directory containing "myext.pyd" to the PYTHONPATH, I still get :

python BdmLsim4.py -i model.xml
Traceback (most recent call last):
  File "BdmLsim4.py", line 6, in <module>
    import myext
ImportError: DLL load failed: module not found.

Many thanks.

Was it helpful?

Solution

It's clearly written in the documentation you linked:

Note that the search path for foo.pyd is PYTHONPATH, not the same as the path that Windows uses to search for foo.dll. Also, foo.pyd need not be present to run your program, whereas if you linked your program with a dll, the dll is required. Of course, foo.pyd is required if you want to say import foo. In a DLL, linkage is declared in the source code with __declspec(dllexport). In a .pyd, linkage is defined in a list of available functions.

So you should either place your .pyd file inside the python's installation directories(site-packages), or you can modify the environmental variable PYTHONPATH and add the directory where the .pyd is placed.

Yet an other alternative is to use .pth files to extend the PYTHONPATH.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top