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
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"),
)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With