【问题标题】:specify *.pyd output path?指定 *.pyd 输出路径?
【发布时间】:2018-12-11 02:35:52
【问题描述】:

this post 中,答案是.c 文件的输出路径。

我想知道如何将.pyd文件全部输出到特定目录(默认与源代码混在一起),例如源代码中的pyd/目录。

【问题讨论】:

  • 并且将 build_dir=“pyd” 添加到 setup-arguments(不是 cythonize 参数)不起作用?在这种情况下,我们需要查看 setup.py。
  • @ead 未知分发选项:'build_dir',在设置函数中

标签: python compilation package cython


【解决方案1】:

您可以将命令行参数--build-lib your/desired/output/path 传递给执行setup.pypython 调用。

此外,此选项与--inplace 不兼容。如果您正在使用它,请将其删除。

【讨论】:

  • python.exe setup.py build_ext --inplace --build-lib pyd/ 不工作
  • @buzhidao 如果不指定--inplace会怎样?
【解决方案2】:

我偶然发现了一个类似的问题并找到了解决方案here

在编写 setup.py 文件时,您可以直接指定命令行参数,而不是在执行期间传递它们:

from psutil import cpu_count
from setuptools import setup
from Cython.Build import cythonize

build_directory = "./build"  # Here you will have your C or C files

pyd_directory = "./pyd/"  # The directory for your pyd file
pyx_name = "your_cython_script.pyx"

setup(
    ext_modules=cythonize(
        pyx_name,
        annotate=True,  # Generate html
        language_level=3,  # Python 3
        nthreads=cpu_count(logical=True),  # Faster compilation
        build_dir=build_directory,
    ),  # Build directory
    options={
        "build": {  # Here you can specify all the command-line arguments
            "build_lib": pyd_directory
        }
    },
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-02
    • 2015-11-20
    • 2014-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多