Bas*_*asj 7 python distutils setuptools cython
python setup.py build与此代码一起使用时:
import setuptools
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules=cythonize("module1.pyx", build_dir="temp"))
Run Code Online (Sandbox Code Playgroud)
.pyd 库是在 .\build\lib.win-amd64-2.7\module1.pyd.
如何使输出.pyd文件到当前文件夹 .?
注意:cythonize参数build_dir="temp"有效:module1.ccython 生成的文件temp\确实在。我的问题是关于输出 .pyd 文件。
谢谢
python setup.py build --help
Run Code Online (Sandbox Code Playgroud)
我发现解决方案是使用参数build-lib:
python setup.py build --build-lib=.
Run Code Online (Sandbox Code Playgroud)
然后 .pyd 文件将在与 .pyx Cython 文件相同的文件夹中创建。
如果您不想将其作为命令行参数传递,也可以这样做:
setup(ext_modules=cythonize("module1.pyx", build_dir="build"), script_args=['build'],
options={'build':{'build_lib':'.'}})
Run Code Online (Sandbox Code Playgroud)
另一种选择inplace是build_ext(它最终做同样的事情):
setup(ext_modules=cythonize("module1.pyx", build_dir="build"), script_args=['build_ext'],
options={'build_ext':{'inplace':True}})
Run Code Online (Sandbox Code Playgroud)
使用参数--dist-dir=[default: dist]选项。
Run Code Online (Sandbox Code Playgroud)--dist-dir (-d) directory to put the source distribution archive(s) in [default: dist]
您可以使用以下内容:
python3 setup.py sdist --dist-dir=your-dir