2016-07-18 25 views
1

I Cython extention, das ich in der folgenden Art und Weise installieren:Wie kann man mit distutils oder setuptools in setup.py eine Cython-Erweiterung importieren (ohne vor jedem Import an sys.path anhängen zu müssen)?

from distutils.core import setup 
from Cython.Build import cythonize 

setup(ext_modules=cythonize(
    "package.pyx", 
    language="c++") 
) 

Wenn ich dieses Paket importiert werden soll, muss ich mit dem Build-Ordner Pfad anhängen:

import sys 
sys.path.append(~/package/build/....) 

Was muss in der Installation geändert werden, damit das Modul in Linux installiert wird und importiert werden kann, ohne an Pfad anhängen zu müssen?

Ich bin auch offen für die Verwendung von setuptools.

+0

'python setup.py build_ext --inplace' sein könnte, was Sie suchen. –

Antwort

2

Probieren Sie meine setup.py als Vorlage ... diese Dinge sind nicht genau dokumentiert. Eine Sache zu erinnern ist hier, wenn Sie inplace bauen Sie wahrscheinlich from projectname.module import module haben:

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')] 
    )