0

I tried several ways to convert a .py file to a .exe, but it always gave me the same problem, namely that the .exe file didn’t work. I found a solution thanks to this post, but it is not specified how to hide the console. Could someone check the post and tell me how to do it?

EDIT:

After searching I found out a solution for my problem:

import cx_Freeze

exe = [cx_Freeze.Executable("game.py", base = "Win32GUI")] # "Win32GUI" -> no console

packages = ["os", "time", "random", "io", "pygame", "base64", "paho.mqtt"]

cx_Freeze.setup(
    name = "ForzaQuattro",
    version = "1.0",
    options = {"build_exe": {"packages": packages,  
        "include_files": []}},
    executables = exe
) 

I used cx_Freeze with the param base="Win32GUI", this will hide the console of the exe file.

After that you will just replace game.py with the name of your python script, replace packages with the package that you need, save that file as setup.py and run by command prompt python setup.py build.

That will genarate a directory with all what you need.

  • https://www.youtube.com/watch?v=lOIJIk_maO4 – Matiiss Apr 03 '21 at 20:26
  • or use this https://pypi.org/project/auto-py-to-exe/ – Matiiss Apr 03 '21 at 20:27
  • @matiiss I tried pyinstaller but this doesn't work. My exe file doesn't open at all. –  Apr 03 '21 at 20:29
  • did You try auto py to exe? – Matiiss Apr 03 '21 at 20:32
  • @matiiss yes, it is the same thing. Auto-py-to-exe uses pyinstaller. –  Apr 03 '21 at 20:33
  • I know but I don't understand why it won't open – Matiiss Apr 03 '21 at 20:34
  • and what do You mean it doesn't open at all, it had to at least show an error message or sth. also is Your program text based (on console?) – Matiiss Apr 03 '21 at 20:36
  • @matiiss my program has a GUI made with pygame, the .py file work properly, instead the exe file once executed does not open. If i use the method in the post linked before, this works, but with the console –  Apr 03 '21 at 20:43
  • I have no idea of how to hide the console in that case, except if You use shortcuts they have the option to minimize the console or sth like that – Matiiss Apr 03 '21 at 20:45
  • @matiiss thanks anyway :) –  Apr 03 '21 at 20:46
  • If `pyinstaller` "doesn't work" I recommend reading the very helpful section of the documentation titled "When things go wrong". – BoarGules Apr 03 '21 at 21:28
  • @BoarGules thank you, btw I found out a solution without using pyinstaller, I editet the post with my solution. –  Apr 04 '21 at 10:23

1 Answers1

0
pyinstaller -w [PathToYourFile]

The -w option hides the console.

  • I tried using pyistaller but this doesn't work, btw i found out a solution –  Apr 04 '21 at 10:18