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 PyInit_foo().
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 PyInit_foo() to initialize it. You do not link your .exe with
foo.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 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.
所以首先要做的是重命名 文件到helloworld.pyx。现在我们需要 创建setup.py,它就像 python Makefile(有关详细信息 见汇编)。你的setup.py应该 看起来像:
用这个来建立你的Cython文件 使用命令行选项:
会在本地留下一个文件 unix中名为helloworld.so的目录 或Windows中的helloworld.dll。
现在到 使用此文件:启动python 解释器并简单地导入 它是一个普通的python模块:
Modifying Python’s Search Path,Absolute and Relative Imports
相关问题 更多 >
编程相关推荐