5

I've been desperately trying to compile my python pygame program into standalone executables to no prevail. PyInstaller doesn't work properly with pygame, Nuitka doesn't make standalones that work and cx_Freeze is looking the best choice. However, when I compile using my setup.py, it makes a set of files but the main executable doesn't run.

My setup.py is as below:

import sys
import cx_Freeze

executables = [cx_Freeze.Executable("main.py")]
images =["assets/images/1.png","assets/images/2.png","assets/images/3.png","assets/images/4.png","assets/images/5.png","assets/images/6.png","assets/images/7.png","assets/images/8.png","assets/images/tile.png","assets/images/mark.png","assets/images/mine.png","assets/images/overlay.png","assets/images/overlay_2.png","assets/images/background.png"]

cx_Freeze.setup(
    name="Minesweeper",
    options={"build_exe": {"packages":["pygame"],
                           "include_files":images}},
    executables = executables

)

There are other python files that are referenced to by main.py; does this matter?

Many thanks

Edit: As requested, platform is Linux (Ubuntu 14.04); python version is 3.4.3; cx_Freeze is cxfreeze 5.0, downloaded through pip. The exact error reads:

Fatal Python error: Py_Initialize: Unable to get locale encoding
Traceback (most recent call last):
File "usr/lib/python3.4/encodings/__init__.py", line 31, in <module>
ImportError: No module named 'codecs'
Aborted (core dumped)
  • What platform? What version of cx_Freeze? What version of Python? What exception (and call stack) are you getting? As long as main.py imports the other Python files with a regular import statement the other files should be found and included automatically. – Anthony Tuininga Mar 23 '17 at 19:57
  • @AnthonyTuininga Appended to question. If you need any more information, just ask –  Mar 23 '17 at 20:25
  • 1
    Ubuntu has a modified Python which conflicts with cx_Freeze, I believe. If you build your own Python instead the problem should go away. If that is the case, please let me know. I'll see if I can get a Ubuntu setup to test on my end as well. – Anthony Tuininga Mar 29 '17 at 15:06
  • @AnthonyTuininga okay, thanks but im not sure exactly how i'd do that. i've found workarounds using other software for now. thanks anyway! –  Mar 29 '17 at 15:12

1 Answers1

1

I had exactly the same issue with cx_Freeze 5.0.1, python 3.4.4 on Ubuntu 15.10. As suggested by @Anthony Tuininga, reinstalling python from the source fixed the problem, for instance from this source :

wget https://www.python.org/ftp/python/3.4.4/Python-3.4.4.tgz
tar xzf Python-3.4.4.tgz

# I had to specify the location of zlib in my case
cd Python-3.4.4
./configure --with-zlib-dir=/usr/lib/x86_64-linux-gnu
sudo make altinstall

Then, I installed cx_Freeze from source :

wget https://github.com/anthony-tuininga/cx_Freeze/archive/5.0.1.tar.gz
tar xzf 5.0.1.tar.gz
cd ./cx_Freeze-5.0.1/
python3.4 setup.py build
sudo python3.4 setup.py install

I also installed pygame from source (as you are using it too) :

wget https://github.com/pygame/pygame/archive/1.9.3.tar.gz
tar xzf 1.9.3.tar.gz
cd ./pygame-1.9.3/
python3.4 setup.py build
sudo python3.4 setup.py install
Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159