# Fatal Python error: (pygame parachute) Segmentation Fault when using PyGame and cx_Freeze

I'm using cx_Freeze to package my PyGame game. I'm running Ubuntu Linux, so I used the source package. However, I got the following error when I run cxfreeze game.py:

Fatal Python error: (pygame parachute) Segmentation Fault
Aborted


How can I fix this? I have seen other similar questions but no good answers.

• A segmentation fault is a fairly severe memory-allocation-based error, which Python generally abstracts from the user. It is very uncommon for one to get this kind of error. cxfreeze is definitely doing something odd. Without seeing its source code, however, we can't know what. Jan 17, 2013 at 0:50

You can fix this by finding out what exactly causes the "pygame parachute".

Your first step to find this out is to add detailed logging to your code. Start off with poor man's print() logging:

print("importing pygame")
import pygame
print("initialising pygame")
pygame.init()
...


With that sort of code you might get an error message like

initialising pygame
Fatal Python error: (pygame parachute) Segmentation Fault
Aborted


which helps you to isolate where the problem happened.

Second, cx_freeze is rather tricky. cxfreeze game.py might not be enough to get a working executable. It is a far better practice to set up a setup.py file. See the source code of the Fabula setup file as an example:

http://code.ohloh.net/file?fid=pqI6bOZhHyHchm4NLxcwxsSxVdA&cid=S_RYKZr4PdY

I don't know about cxfreeze but your problem might not be specific to it. In my case running under gdb provided a hint:

root@beczulka:/# gdb python3
[...]
(gdb) r -c 'import pygame;pygame.init()'
Starting program: /usr/bin/python3 -c 'import pygame;pygame.init()'
pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
No protocol specified
No protocol specified
No protocol specified

0x00007ffff70427b4 in caca_free_display () from /usr/lib/x86_64-linux-gnu/libcaca.so.0
(gdb) bt
#0  0x00007ffff70427b4 in caca_free_display () from /usr/lib/x86_64-linux-gnu/libcaca.so.0
#1  0x00007ffff7043460 in __caca0_end () from /usr/lib/x86_64-linux-gnu/libcaca.so.0
#2  0x00007ffff7803c0c in ?? () from /usr/lib/x86_64-linux-gnu/libSDL-1.2.so.0
#3  0x00007ffff77e173e in SDL_VideoQuit () from /usr/lib/x86_64-linux-gnu/libSDL-1.2.so.0
#4  0x00007ffff77e1b03 in SDL_VideoInit () from /usr/lib/x86_64-linux-gnu/libSDL-1.2.so.0
#5  0x00007ffff77bad84 in SDL_InitSubSystem () from /usr/lib/x86_64-linux-gnu/libSDL-1.2.so.0
#6  0x00007ffff784d41a in ?? () from /usr/lib/python3/dist-packages/pygame/base.cpython-37m-x86_64-linux-gnu.so
#7  0x00007ffff784d4b0 in ?? () from /usr/lib/python3/dist-packages/pygame/base.cpython-37m-x86_64-linux-gnu.so
#8  0x00000000005d6e51 in _PyMethodDef_RawFastCallKeywords ()
#9  0x000000000054b620 in ?? ()
#10 0x0000000000552a01 in _PyEval_EvalFrameDefault ()
#11 0x000000000054bfa2 in _PyEval_EvalCodeWithName ()
#12 0x000000000052e2ff in PyRun_StringFlags ()
#13 0x000000000062fc5d in PyRun_SimpleStringFlags ()
#14 0x0000000000652a08 in ?? ()
#15 0x0000000000652b3e in _Py_UnixMain ()
#16 0x00007ffff7a2009b in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
#17 0x00000000005e026a in _start ()
(gdb)


The name caca_free_display made me realize I was trying to run without a display. Running in an X session, with a DISPLAY set made it work.

It should be an error related to C implementation. Please see if the following command works:

apt-get install -y xserver-xorg


import pygame I just did this and it works.

• General Notice: if you're going to continue to downvote this answer, please provide a reason. Since the asker failed to provide code samples, this answer is about all that we can assume. Downvoting without explanation also prevents new users from understanding how they can improve in the future. Welcome to GameDev, Naidu! Jan 15, 2018 at 19:08