I am a newbie to cython.
I've the following directory structure.
cython_program/
cython_program/helloworld.py
cython_program/lib/printname.py
helloworld.py:
import lib.printname as name
def printname():
name.myname()
printname.py:
def myname():
print("this is my name")
setup.py:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [
Extension("helloworld", ["helloworld.py"]),
Extension("mod", ["./lib/printname.py"]),
]
setup(
name = 'My Program',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)
The problem I am having is that when I compile my program using python setup.py build_ext --inplace
in the cython_program
directory. It does compile the program successfully and generates a printname.c
file in the lib folder.
But when I move the printname.py and helloworld.py to a separate folder to make sure that my cython compiled code is running. It gives me the following error ImportError: No module named lib.printname
.
Why isn't it compiling the module(lib.printname) also with the main helloworld.py
file ?
Note: This works fine if I keep both helloworld.py and printname.py in the same folder.
Thanks in advance.
It was a simple issue in setup.py
.
Changed this line:
Extension("mod", ["./lib/printname.py"]),
To This:
Extension("lib.printname", ["./lib/printname.py"]),
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