I am using PyCharm. I have a python script in the following location:
C:\Users\XYZ\PycharmProjects\Project1\playground.py
playground.py
only has a line of code as shown below:
import PyTbl
In the Project1
folder there's another file:
C:\Users\XYZ\PycharmProjects\Project1\PyTbl.pyd
When I run the Python script playground.py
I get the following error:
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "C:/Users/XYZ/PycharmProjects/Project1/playground.py", line 1, in <module>
import PyTbl
SystemError: initialization of PyTbl raised unreported exception
If I hover my mouse over the line of Python code in playground.py
in the PyCharm editor I get the following error message:
"No module named PyTbl"
Any idea how should I import a .pyd
file into a Python script?
.pyd
is basically a Windows .dll
file.
.pyd
files aredll’s
, but there are a few differences. If you have a DLL named foo.pyd, then it must have a functionPyInit_foo()
. You can then write Pythonimport foo
, and Python will search forfoo.pyd
(as well asfoo.py
,foo.pyc
) and if it finds it, will attempt to callPyInit_foo()
to initialize it. You do not link your .exe withfoo.lib
, as that would cause Windows to require the DLL to be present.Note that the search path for
foo.pyd
is PYTHONPATH, not the same as the path that Windows uses to search forfoo.dll
. Also,foo.pyd
need not be present to run your program, whereas if you linked your program with adll
, thedll
is required. Of course,foo.pyd
is required if you want to sayimport foo
. In a DLL, the linkage is declared in the source code with__declspec(dllexport)
. In a.pyd
, linkage is defined in a list of available functions.