2014-11-29 2 views
2

다음 파일을 setup.py로사이 썬 ImportError를, 또는 경로 오류 helloworld.pyx로

print("Hello World") 

다음 파일을

from distutils.core import setup 
from distutils.extension import Extension 
from Cython.Distutils import build_ext 
ext_modules = [Extension("helloworld",["helloworld.pyx"] 
setup(
    name = 'HW', 
    cmdclass = {'build_ext': build_ext}, 
    ext_modules = ext_modules 
) 

내가

를 .so 파일 내 *를 가지고 python setup.py build_ext --inplace을 사용한 후

따라서 짧은 가져 오기 이름을 얻으려면 * .so를 hw.so로 바꿉니다.

하지만 python을 SART에서 입력 한 경우 : 3 시간 전

ImportError: dynamic module does not define init function (PyInit_hw) 

나는 정확한 건 한판 승부를하고 있었다 모두가 괜찮다고 : import hw 나는이 오류가 발생했습니다. 하지만 난이 측면에서 뭔가를 tryed : 내가 뭔가를 해결하고 싶었 기 때문에

cmake -DPYTHON_EXECUTABLE=$(which python2) \ 
-DPYTHON_INCLUDE_DIR=$(echo /usr/include/python2*) \ 
-DPYTHON_LIBRARY=$(echo /usr/lib/libpython2.*.so) \ 

:

http://sourceforge.net/p/ubertooth/mailman/message/31699880/ 나는 다음을 tryed. 나는 "3"으로 모든 "2"를 바꿨다. python3.4와 함께 일하고있다.

내가 이것을 만든 후에 나는 항상 위의 오류가 발생했다. 나는 어떤 길을 파괴 했습니까? 어떻게 취소 할 수 있습니까? 내 나쁜 영어에 대한

죄송합니다

아서 도와 U 감사 : P

답변

2

우리가 볼 "C 나 C++과 파이썬 확장"에 파이썬 3 설명서를 보면 그

The initialization function must be named PyInit_name(), where name is the name of the module, and should be the only non-static item defined in the module file.

(https://docs.python.org/3/extending/extending.html#the-module-s-method-table-and-initialization-function)

즉, init 함수를 변경하지 않고 모듈의 파일 이름을 변경할 수는 없습니다. 우선 모듈을 최종 이름으로 컴파일해야합니다. 컴파일 한 후 .so 파일의 이름을 바꾸면 작동하지 않습니다.

+0

대단히 감사합니다. 전 자신을 둘러 보며 알지요. 그러나 설명서 링크를 위해, 나는 그 statemant를 찾지 못했습니다. 몇 시간의 시행 착오 연구를 구했을 것입니다 : P – Speedy