Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cython No such file or directory: '.pyd' error on Windows

Tags:

python

cython

I'm trying to build the Hello World example from Cython tutorial. I have written both hello.pyx and setup.py files:

# 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"),
)

When I run

python setup.py build_ext --inplace

I get the following error:

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'

Build process works fine and I get a working hello.pyd file, but for some reason setup.py cannot copy the .pyd back into the working directory. How can I fix that?

hello.pyx and setup.py files are also available at BitBucket

like image 611
Ivan Gromov Avatar asked Aug 02 '15 20:08

Ivan Gromov


Video Answer


2 Answers

I've solved this issue. It appeared that python setup.py command should be executed outside the project directory. The following code works fine.

cd ..
python setup.py build_ext --inplace

UPDATE: a better way to solve the issue is to specify the package_dir option to setup function:

setup(
    name='Hello world app',
    package_dir={'cython_test': ''},
    ext_modules=cythonize("hello.pyx"),
)
like image 108
Ivan Gromov Avatar answered Oct 19 '22 06:10

Ivan Gromov


Hopefully this will be useful to others experiencing this error. After some digging, my problem was due the __init__.py file in the same directory. This github issue highlights the potential problem. After removing the __init__.py, I now get the correct .pyd file in the directory.

like image 41
Josmoor98 Avatar answered Oct 19 '22 07:10

Josmoor98