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

535 views
Skip to first unread message

Pierre Augier

unread,
Jun 23, 2014, 6:36:19 AM6/23/14
to cython...@googlegroups.com

Hello,

I try to use Cython with Python3 (Anaconda3) under Windows 7. After having solved a problem 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():
    print('Hello')

it gives

In [1]: import testcython # no crash here

In [2]: testcython.say_hello()
Hello

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?

I am quite stuck and really need some help on this...

PS: This problem is specific to Python 3 (Anaconda) under Windows. No problem with Python 2.7 (Anaconda) under Windows and no problem with Python 3 (Anaconda) under Linux.

Sturla Molden

unread,
Jun 23, 2014, 3:00:59 PM6/23/14
to cython...@googlegroups.com
Pierre Augier <pierre.a...@gmail.com> wrote:

> <p>Does anyone understand what happens here with Cython, Python 3 (Anaconda=
> 3) under Windows?</p><p>I am quite stuck and really need some help on this.=
> ..<br></p>

You are probably using the wrong MSVC version for Python 3 and get a CRT
conflict. I would gess Python 2.7 is compiled with VS2008 and Python 3 is
compiled with VS2010. Make sure you use the correct MSVC version or get
MinGW or TDM-GCC (it always links the correct CRT).

Sturla

Pierre Augier

unread,
Jun 24, 2014, 9:25:04 AM6/24/14
to cython...@googlegroups.com
Sturla Molden wrote :

Thank you Sturla. You are right about the compilers used to compile the 2 versions of Python:
Python 2.7.5 |Anaconda 1.8.0 (64-bit)| (default, Jul  1 2013, 12:37:52) [MSC v.1500 64 bit (AMD64)]
Python 3.4.1 |Anaconda 2.0.1 (64-bit)| (default, Jun 11 2014, 17:27:11) [MSC v.1600 64 bit(AMD64)]

But I already use MinGW.
C:\>"C:\Prog\Anaconda3\Scripts\gcc.bat" --version
gcc.exe (GCC) 4.7.0 20111220 (experimental)

and C:\Prog\Anaconda3\Scripts\gcc.bat just runs C:\Prog\Anaconda3\MinGW\bin\gcc.exe

Why does MinGW not link the correct CRT?

Sturla Molden

unread,
Jun 24, 2014, 3:31:44 PM6/24/14
to cython...@googlegroups.com
Pierre Augier <pierre.a...@gmail.com> wrote:

> Python 3.4.1 |Anaconda 2.0.1 (64-bit)| (default, Jun 11 2014, 17:27:11) [MS=
> C v.1600 64 bit(AMD64)]<br><br>But I already use MinGW. <br>C:\&amp;gt;"C:\Prog=
> \Anaconda3\<wbr>Scripts\gcc.bat" --version<br>
> gcc.exe (GCC) 4.7.0 20111220 (experimental)<br><br>and C:\Prog\Anaconda3\<w=
>> Scripts\gcc.bat just runs C:\Prog\Anaconda3\<wbr>MinGW\bin\gcc.exe<br><b=
>> Why does MinGW not link the correct CRT?<br><br></div></div>

I think it does.

Sorry, then I have no idea what is going on. I have never seen this problem
on Windows myself. Ask Continuum for help with Anaconda.

Sturla

Pierre Augier

unread,
Jun 25, 2014, 3:17:08 AM6/25/14
to cython...@googlegroups.com
Using the module faulthandler, I get more information.

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
it crashes and I obtain the tracebacks:

$ 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>

In the Anaconda mailing list, I got this answer:

"This looks like a Cython bug. The Python import mechanism was
rewritten in Python 3 to be pure Python, so it's not surprising that
the behavior is different in Python 2.

You might try the cython mailing list and see if anyone there has any thoughts."

Is anyone has any thoughts?







--

---
You received this message because you are subscribed to a topic in the Google Groups "cython-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cython-users/VnbIV7UsFtA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cython-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert Bradshaw

unread,
Jun 29, 2014, 2:27:01 AM6/29/14
to cython...@googlegroups.com
Can you reproduce this not using Anaconda3? Cython has supported
Python 3 ever since it was released.
> You received this message because you are subscribed to the Google Groups
> "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an

Tod Haren

unread,
Apr 12, 2016, 2:39:12 AM4/12/16
to cython-users
So nearly two years later this problem still seems unresolved. My solution was to add -DMS_WIN64 to the gcc command line when compiling and linking.  I am using an up-to-date install of Miniconda3, Python 3.4 64 bit with a recent install of MinGW-w64.

For example:

>gcc -shared -I conda_py34_amd64\include -L conda_py34_amd64 -l python34 -DMS_WIN64 -o cython_test.pyd cython_test.c

Or if you are using distutils with a setup.py you can add this to the define_macros argument:

extensions = [Extension( ..., define_macros=[('MS_WIN64', None), ])]
Reply all
Reply to author
Forward
0 new messages