ichthyophile
ichthyophile

Reputation: 111

Cython Hello World: Module Not Found; helloworld.pyd not created

I've looked at the other Cython "Hello World" questions and their errors are very different than mine. I apologize if this is a duplicate question -- I'd love to see what I'm duplicating because I've looked all over. I'm following the instructions here: https://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html

Here's my helloworld.pyx:

print("Hello World")

My setup.py:

from setuptools import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize("helloworld.pyx")
)

I went to the command line and ran python setup.py build_ext --inplace, then ran `import helloworld' in the Spyder console (and then in a Jupyter notebook, just in case).

Error:

Traceback (most recent call last):

  File "<ipython-input-1-39f3e3c18221>", line 1, in <module>
    import helloworld

ModuleNotFoundError: No module named 'helloworld'

The tutorial said the command should have created a file called helloworld.pyd, so I searched my entire computer for that file and found nothing.

I'm using Python 3.7.3 on 64-bit Windows. Any help would be appreciated.

Upvotes: 0

Views: 998

Answers (1)

Leo Pfeiffer
Leo Pfeiffer

Reputation: 76

You could use Extension in your setup.py file, such that you have:

# setup.py

from setuptools import setup, Extension
from Cython.Build import cythonize

extensions = [Extension('helloworld', ["helloworld.pyx"])]

setup(ext_modules = cythonize(extensions))

Then run python setup.py build_ext --inplace again and the error should be gone, i.e. the module should be found.

Upvotes: 1

Related Questions