Cython没有这样的文件或目录:' .pyd' Windows上的错误

时间:2015-08-02 20:04:55

标签: python cython

我试图从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

获取

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:2)

我已经解决了这个问题。看来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"),
)