Python C extension: Use extension PYD or DLL?
pyd files are just dll files ready for python importing.
To distinguish them from normal dlls, I recommend .pyd not .dll in windows.
Here is the official doc about this issue:
http://docs.python.org/faq/windows.html#is-a-pyd-file-the-same-as-a-dll
According to the Creating Your Own Project step (Step 7 of "The Cookbook Approach") of Building C and C++ Extensions on Windows
The output file should be called spam.pyd (in Release mode) or spam_d.pyd (in Debug mode). The extension .pyd was chosen to avoid confusion with a system library spam.dll to which your module could be a Python interface.
So a .pyd file is just a DLL renamed to save on confusion.
On linux however, speaking from experience it seems that you need to use the .so extension for python dlls. This is just a standard unix shared library. I can't provide a source or reason for why python on linux does not change the file extension, however I can show you how to demonstrate it. At the shell, run the following:
python -vv>>> import fakemodule
You'll notice that the output shows:
trying /usr/lib/python2.5/site-packages/fakemodule.so
Presuming your Python extension foo
is intended to be used as a module, accessible via import foo
, you don't need to know what the filename extension should be on what operating system. You just use distutils
. You will get a .pyd on Windows, and a .so on Linux etc. Read this documentation.
Update in response to comment by @gecco
import foo is working both both extension types: dll and pyd. The extension does not matter here... :
For me (Python 2.7.1, Windows 7), python -vv
shows only pyd, py, pyw and pyc extensions (in that order) being searched. If I have foo.pyd
in C:\python27\lib\site-packages
, import foo
works. If I rename that file to foo.dll
, import foo
fails.