繁体   English   中英

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

[英]Python crash with minimal Cython module (Python3, Anaconda3, Windows7)

我尝试在Windows 7下使用Cython和Python3(Anaconda3)。通过编辑文件cygwinccompiler.py解决了distutils中的错误(参见在Windows 7下使用python 3.3(Anaconda)构建最小的cython文件 ),可以构建模块没有任何问题:

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>

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

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

你能在Linux下工作吗:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM