Python崩溃与最小的Cython模块(Python3,Anaconda3,Windows7)

时间:2014-06-21 08:56:10

标签: python-3.x windows-7 cython anaconda

我尝试在Windows 7下使用Cython和Python3(Anaconda3)。通过编辑文件cygwinccompiler.py(参见Building minimal cython file with python 3.3 (Anaconda) under windows 7)解决了distutils中的错误后,可以毫无问题地构建模块: / p>

C:\path\testcython> python setup.py build 
running build
running build_ext
cythoning testcython.pyx to testcython.c
building 'testcython' extension
C:\Prog\Anaconda3\Scripts\gcc.bat -mdll -O -Wall -IC:\Prog\Anaconda3\include -IC
:\Prog\Anaconda3\include -c testcython.c -o build\temp.win-amd64-3.4\Release\tes
tcython.o
writing build\temp.win-amd64-3.4\Release\testcython.def
C:\Prog\Anaconda3\Scripts\gcc.bat -shared -s build\temp.win-amd64-3.4\Release\te
stcython.o build\temp.win-amd64-3.4\Release\testcython.def -LC:\Prog\Anaconda3\l
ibs -LC:\Prog\Anaconda3\PCbuild\amd64 -lpython34 -lmsvcr100 -o build\lib.win-amd
64-3.4\testcython.pyd

但是,只要.pyx文件中有import或print语句,生成的.pyd文件就会导致Python崩溃。例如,如果testcython.pyx包含

def say_hello_to(name):
    print('Hello '+name)

它给出了

In [1]: import testcython # no crash here

In [2]: testcython.say_hello_to('Tom')
Hello Tom

这里" Python.exe已停止工作"窗口弹出,它已经完成。

在那种情况下(没有错误日志崩溃,我猜想分段错误),我该怎么做才能理解这个问题?

有没有人理解在Windows下使用Cython,Python 3(Anaconda3)会发生什么?

PS:Python 2.7(Anaconda)没问题。


编辑:模块faulthandler生成的回溯

如果testcython.pyx只包含:

print('Test print... Will it crash?')

import mod # where mod.py is a nearly empty module in the working directory

import sys

python崩溃了,我得到了:

$ python -X faulthandler -c 'import testcython'
Test print... Will it crash?
Fatal Python error: Segmentation fault

Current thread 0x000013e0 (most recent call first):
  File "<frozen importlib._bootstrap>", line 321 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1715 in load_module
  File "<frozen importlib._bootstrap>", line 539 in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1161 in _load_backward_compatible
  File "<frozen importlib._bootstrap>", line 1191 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 2226 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 2237 in _find_and_load
  File "<string>", line 1 in <module>

1 个答案:

答案 0 :(得分:1)

似乎构建无法链接到相应的库,并且print(写入终端)导致seg-faults。

让我们回到构建过程。你可以使用pip而不是setup.py build吗?

你能在Linux下工作吗?)