2017-02-08 1 views
0

Windows에서 .pyx로 저장 한 Cython 파일 (.pyx)을 컴파일하려고합니다. 여기 내 프로젝트 디렉토리 경로입니다.Cython 컴파일 오류가 "유효한 모듈 이름이 아닙니다."

c:\..\Project\App\Analyzer\ 
_init_.py 
Few_other_files.py 
consolidated_loop_C.pyx 
cl_setup.py 

는 여기에 내가 같은 폴더에 compling을 위해 문 아래 사용하고 내 cl_setup.py

from Cython.Build import cythonize 
try: 
    from setuptools import setup 
    from setuptools import Extension 
except ImportError: 
    from distutils.core import setup 
    from distutils.extension import Extension 


setup(
    name = "Consolidated Loop", 
    ext_modules = cythonize("consolidated_loop_C.pyx") 
) 

입니다.

python cl_setup.py build_ext --inplace 

하지만 아래 오류가 나타납니다. 내 생각 엔 cythonize()에 특정 매개 변수가 누락되어 행운없이 연구하려고했습니다.

enter image description here

+0

경로에서 대시를 찾아서 그것에 대해 불만을 토로하고 있습니다 (동일한 문제는 http://stackoverflow.com/questions/32799506/something-wrong-when-i-compile-cython-with-c 참조). 왜 정확히 그것을하고 있는지 나는 잘 모르겠습니다. 간단한 해결책은 디렉토리의 이름을 바꾸는 것입니다 (하지만 실제로는 적절한 해결책이 아닙니다. 그렇게하지 않아도됩니다). – DavidW

+0

@DavidW 예, 폴더 이름에 대시가 맞았습니다. 지금은 폴더의 이름을 바꿨습니다. 감사. – PyRaider

답변

1

첫째, 단지 사용에 setup.py 파일을 변경의 distutils

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

setup(
    name = "Consolidated Loop", 
    ext_modules = cythonize("consolidated_loop_C.pyx") 
) 

이 잠재적 repliers에 대한 디버깅을 촉진하는 것입니다.

그런 다음 몇 가지 실험과 다른 SO 게시물 Python building cython extension with setup creates subfolder when __init__.py exists 내가 하위 디렉토리에있는 당신의 사이 썬 파일을 이동하거나 __init__.py 파일을 제거하거나 제안

The command `python setup.py build_ext --inplace` always create a new directory에서. 후자의 문제는 파이썬이나 Cython으로 하여금 현재 디렉토리 모듈의 이름을 추측하게 할 것이다. 또한 setup.py 파일이 모듈의 디렉토리에 존재할 수 없으며 이로 인해 문제가 발생합니다.

코드를 배포하거나 패키지화하려는 경우 이전 옵션 (자신의 __init__.py 등으로 하위 디렉토리의 파일을 깨끗하게 이동하는 것)이 바람직합니다. 그렇지 않으면 __init__.py을 삭제하고 완료하십시오. 이렇게하면 build_ext --inplace으로 로컬에서 사용할 수있는 파이썬 모듈 consolidated_loop_C.so이 생성됩니다.

관련 문제