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


I try to use Cython with Python3 (Anaconda3) under Windows 7. After having solved a bug in distutils by editing the file (cf. Building minimal cython file with python 3.3 (Anaconda) under windows 7), modules can be built without any problems:

C:\path\testcython> python 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\\Release\tes
writing build\\Release\testcython.def
C:\Prog\Anaconda3\Scripts\gcc.bat -shared -s build\\Release\te
stcython.o build\\Release\testcython.def -LC:\Prog\Anaconda3\l
ibs -LC:\Prog\Anaconda3\PCbuild\amd64 -lpython34 -lmsvcr100 -o build\

However, as soon as there is an import or a print statement in the .pyx file, the produced .pyd file makes Python crash. For example, if testcython.pyx contains

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

it gives

In [1]: import testcython # no crash here

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

Here the "Python.exe has stopped working" window pops up and it's finished.

In that kind of situation (crash without error log, segmentation fault I suppose), what can I do to understand the problem?

Does anyone understand what happens here with Cython, Python 3 (Anaconda3) under Windows?

PS: no problem with Python 2.7 (Anaconda).

Edit: traceback produced by the module faulthandler

If testcython.pyx just contains:

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


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


import sys

python crashes and I get:

$ 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>
asked on Stack Overflow Jun 21, 2014 by paugier • edited May 23, 2017 by Community

1 Answer


It seems like the build is failing to link to the appropriate libraries and the print (write to terminal) is causing seg-faults.

let's go back to the build process. can you use pip instead of build?

Can you work under Linux :)

answered on Stack Overflow Mar 31, 2015 by Jonathan

User contributions licensed under CC BY-SA 3.0