我有以下列方式安装的cython扩展:
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules=cythonize(
"package.pyx",
language="c++")
)
当我想导入此包时,我需要使用以下命令将build文件夹附加到路径:
import sys
sys.path.append(~/package/build/....)
在安装中需要更改哪些内容才能将模块安装到Linux中并且可以导入而无需附加到路径?
我也愿意使用setuptools。
答案 0 :(得分:2)
尝试将我的setup.py
作为模板......这些内容并没有完整记录。这里要记住的一件事是,如果你构建inplace
,你可能需要from projectname.module import module
:
try:
from setuptools import setup
from setuptools import Extension
except ImportError:
from distutils.core import setup
from distutils.extension import Extension
module = 'MyModuleName' # this assumes your .pyx and your import module have the same names
# ignore the below extra options if you don't need them (i.e. comment out `#`)
ext_modules = [Extension(module, sources=[module + ".pyx"],
include_dirs=[],
library_dirs=[],
extra_compile_args=[],
language='c++')]
setup(
name = module,
ext_modules = ext_modules,
cmdclass = {'build_ext': build_ext},
include_dirs = [np.get_include(), os.path.join(np.get_include(), 'numpy')]
)