【问题标题】:Cython No such file or directory: '.pyd' error on WindowsCython 没有这样的文件或目录:Windows 上的“.pyd”错误
【发布时间】:2015-10-24 21:33:15
【问题描述】:

我正在尝试从 Cython 教程构建 Hello World example。 我已经编写了 hello.pyx 和 setup.py 文件:

# hello.pyx
def say_hello_to(name):
    print("Hello %s!" % name)

# setup.py
try:
    from setuptools import setup
    from setuptools import Extension
except ImportError:
    from distutils.core import setup
    from distutils.extension import Extension

from Cython.Build import cythonize


setup(
  name='Hello world app',
  ext_modules=cythonize("hello.pyx"),
)

当我跑步时

python setup.py build_ext --inplace

我收到以下错误:

copying build\lib.win-amd64-2.7\cython_test\hello.pyd -> cython_test
error: [Errno 2] No such file or directory: 'cython_test\\hello.pyd'

构建过程运行良好,我得到了一个有效的 hello.pyd 文件,但由于某种原因 setup.py 无法将 .pyd 复制回工作目录。我该如何解决?

hello.pyx 和 setup.py 文件也可在 BitBucket

获得

【问题讨论】:

    标签: python cython


    【解决方案1】:

    我已经解决了这个问题。看来python setup.py 命令应该在项目目录之外执行。以下代码运行良好。

    cd ..
    python setup.py build_ext --inplace
    

    更新:解决问题的更好方法是将package_dir 选项指定给setup 函数:

    setup(
        name='Hello world app',
        package_dir={'cython_test': ''},
        ext_modules=cythonize("hello.pyx"),
    )
    

    【讨论】:

      【解决方案2】:

      希望这对遇到此错误的其他人有用。经过一番挖掘,我的问题是由于同一目录中的__init__.py 文件。 This github issue 突出了潜在问题。删除__init__.py 后,我现在在目录中得到了正确的.pyd 文件。

      【讨论】:

        猜你喜欢
        • 2016-04-12
        • 2013-01-17
        • 2020-04-18
        • 2021-11-05
        • 1970-01-01
        • 2021-10-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多