The .pyd file is the DLL itself on Windows

The ** .pyd file is the DLL itself ** on Windows, isn't it? I learned a lot.

When importing a function created in C ++ using Pybind11 on Windows, create a Visual Studio project of the type that creates a DLL in C ++, and code containing PYBIND11_PLUGIN (...) {...} Add, build, generate DLL, rename the generated ** DLL from .dll to .pyd **, place .pyd in the same folder as the .py script file, and use the file name from within the .py script It's a mechanism that can be imported.

(I think that d in .pyd is d? In DLL ... Then, .pydll is easier to understand and it is a Windows-only story, so I wonder if it is different ...)

Quoted below:


Extend C ++ to Python with Pybind 11 https://www.366service.com/jp/qa/9c02528547c8067355edf43854e3fd4e

In Python, the name of the .pyd file must be the same as the internal module. From the documentation (https://docs.python.org/2/faq/windows.html):

If you have a DLL ** named> ** foo.pyd, you need the function initfoo (). Then you can write Python "import foo", which will search for foo.pyd (similar to foo.py, foo.pyc) and if found it will try to initialize it by calling initfoo ().


Test using C ++ class from Python (pybind11 version) https://qiita.com/tibigame/items/499a81f0e1cb47962b90

After build ** rename "ClassTestLib.dll" to "ClassTestLib.pyd" ** Copy the python code to the directory containing it.


Python on Windows FAQ https://docs.python.org/2/faq/windows.html#is-a-pyd-file-the-same-as-a-dll

Is a *.pyd file the same as a DLL?

Yes, .pyd files are dll’s, but there are a few differences. If you have a DLL named foo.pyd, then it must have a function initfoo(). You can then write Python “import foo”, and Python will search for foo.pyd (as well as foo.py, foo.pyc) and if it finds it, will attempt to call initfoo() to initialize it. You do not link your .exe with foo.lib, as that would cause Windows to require the DLL to be present.

[Translate with DeepL ↓](https://www.deepl.com/ja/translator#en/ja/Is%20a%20*.pyd%20file%20the%20same%20as%20a%20DLL%3F%0A%0AYes%2C%20.pyd%20files%20are%20dll%E2%80%99s%2C%20but%20there%20are%20a%20few%20differences.%20If%20you%20have%20a%20DLL%20named%20foo.pyd%2C%20then%20it%20must%20have%20a%20function%20initfoo().% 20You% 20can% 20then% 20write% 20Python% 20% E2% 80% 9Cimport% 20foo% E2% 80% 9D% 2C% 20and% 20Python% 20will% 20search% 20for% 20foo .pyd% 20 (as% 20well% 20as% 20foo.py% 2C% 20foo.pyc)% 20and% 20if% 20it% 20finds% 20it% 2C% 20will% 20attempt% 20to% 20call% 20initfoo ()% 20to% 20initialize% 20it.% 20You% 20do% 20not% 20link% 20your% 20.exe% 20with% 20foo.lib% 2C% 20as% 20that% 20would% 20cause% 20Windows% 20to% 20require% 20the% 20DLL% 20to% 20be% 20 present.% 0A)

Is the .pyd file the same as the DLL?

Yes, the .pyd file is a DLL, but there are some differences. If you have a DLL named foo.pyd, it must have the initfoo () function. If you write "import foo" in Python, Python will search for foo.pyd (and foo.py, foo.pyc) and if it finds it, it will call initfoo () to try to initialize it. Do not link .exe and foo.lib.

Recommended Posts

The .pyd file is the DLL itself on Windows
Python CGI file created on Windows
On Linux, the time stamp of a file is a little past.
The one who is not on DVD
Run yolov4 "for the time being" on windows
Have pandas read the zip file on the web
Until the Sphinx documentation is published on GitHub
Python on Windows
Check if the LAN cable is disconnected on Linux
Check "[Windows] How to tell if the exe is x64 or x86 Part2" on MacOS Go
Workaround for the problem that sys.argv is not passed when executing a Python script with only the file name in Python2.7 on Windows