使用cython扩展一旦编译[在Windows下],如何使用.pyd?

2024-10-01 11:29:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Linux下使用Cython编译自制的python扩展。在Linux上,我使用distutils生成一个“我的下一个,然后我可以简单地将其添加到我的PYTHONPATH中并获得import myextpython调用。在

现在,我正在尝试让它在Windows7下工作(使用Cython0.18)。 我成功地运行了distutils,现在我得到了一个myext.pyd文件。但似乎(http://docs.python.org/2/faq/windows.html#is-a-pyd-file-the-same-as-a-dll)将路径添加到“我的文字.pyd“在窗户下面是不够的。什么应该是“我的下一页“看起来,或者换句话说,在Python(2.7)安装中获得可用扩展的过程是什么。在

注意:添加包含我的文字.pyd“对于Python,我仍然得到:

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.

非常感谢。在


Tags: 文件pyimporthttplinuxcythonpydmodule
1条回答
网友
1楼 · 发布于 2024-10-01 11:29:03

你链接的文档中清楚地写着:

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.

因此,您应该将.pyd文件放在python的安装目录(site-packages)中,或者修改环境变量PYTHONPATH,并添加{}所在的目录。在

另一种选择是使用.pth文件来扩展PYTHONPATH。在

相关问题 更多 >