1
我是cython的新手。Cython編譯模塊在單獨的目錄中
我有以下目錄結構。
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
)
我遇到的問題是當我在cython_program
目錄中使用python setup.py build_ext --inplace
編譯我的程序時。它會成功編譯程序並在lib文件夾中生成printname.c
文件。
但是,當我將printname.py和helloworld.py移動到一個單獨的文件夾以確保我的cython編譯代碼正在運行。它給我以下錯誤ImportError: No module named lib.printname
。
爲什麼不編譯模塊(lib.printname)也與主helloworld.py
文件?
注意:如果我將helloworld.py和printname.py保留在同一個文件夾中,此工作正常。
在此先感謝。
考慮接受你自己的答案...... –