-1

I tried to make my game into a .exe file using this tutorial: How can I convert a .py to .exe for Python? but when i open it it gives an error: fatal python error: init_fs_encoding: failed to get the python codec of the filesystem encoding Python runtime state: core initialised

The code has No errors, it has a lot of weak warnings though. Also in the code i import images, music, sounds, librarys, python files and text files.

Pycharm shows the error: cx_Freeze not found in the setup.py file made from the How can I convert a .py to .exe for Python? tutorial. I have installed cx_Freeze and idna using pip. Also i can convert other files to a working .exe file, but this one doesn't work. Thanks for your help!

1 Answers1

0
import cx_Freeze
from cx_Freeze import * 

setup (
    name = "File name",
    options = {'build_exe':{'packages': ['pygame']}},
    executables = [
        Executable(
            "filename.py",

        )

    ]

)

This should be enough to convert it but if you want you can look up a more detailed syntax with more commands.

Save that as Setup.py or anything that you want.

Then create another file and type the following

py Setup.py build

save this as build.bat. Make sure you save it as .bat file. Then open up the build file that is created and your exe file will be ready in a few mins. Please follow this and make sure you have cx_freeze installed

rishi
  • 643
  • 5
  • 21
  • When i do this and open the executable file is says: pygame.error: couldn't open person.png – Tommy van sante Jun 05 '20 at 13:43
  • @Tommyvansante Did you put all your pictures and files in the same folder as the exe? Because I have tested this with a decently large project with loads of pictures and imports/libraries. – rishi Jun 05 '20 at 14:07
  • I did this, Now it works on a computer with python installed, but on a other computer it doesn't. – Tommy van sante Jun 06 '20 at 08:39
  • @Tommy van sante It will work, make sure to put all your dependencies in the same folder. I hope you listed all your imports in packages while creating the exe(Setup.py). If it still doesn't work please tell me in detail what's happening. – rishi Jun 06 '20 at 14:16