I try to use Cython with Python3 (Anaconda3) under Windows 7. After having solved a bug in distutils by editing the file cygwinccompiler.py (cf. Building minimal cython file with python 3.3 (Anaconda) under windows 7), modules can be built without any problems:
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
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?')
or
import mod # where mod.py is a nearly empty module in the working directory
or
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>
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 setup.py build?
Can you work under Linux :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With