Python Script To Executable With Cx_freeze, Exe Does Nothing
Solution 1:
Remove the two lines
if sys.platform == "win32":
base = "Win32GUI"
from your setup script and it should work.
base = "Win32GUI"
tells cx_Freeze
not to start a console window and should be used only if the main application starts a GUI (e.g. with PySide, PyQt, Tk, ...). It presumably also redirects the standard output away from the console if you run the executable from an already started console. In your case you have a console-based application and you thus want a console to be started and to receive the standard output. This behavior is partially explained in the cx_Freeze
documentation.
Now if you run your executable without using the cmd (e.g. by double-clicking it in Windows-Explorer), it starts a console window, prints the output there, and closes the console immediately when the execution is finished. In your example script, you would like to have the time to read the output before the console closes, so what you need then is something to tell your script to wait before finishing, for example until you press a key. You can add
input("Press Enter to continue...")
at the end of your script for this purpose, see How do I make python to wait for a pressed key.
Solution 2:
Add wait after the code so it doesn't finish immediately.
import random
import stringfor i in range(20):
k = random.choice(string.ascii_letters)
j = random.randint(0, 9)
z = random.randint(1, 2)
if z == 1:
x = k
if z == 2:
x = j
print(x, end=" ")
import timetime.sleep(5) #<-- Sleep for 5 seconds
You can also use my Python Executable maker.
Post a Comment for "Python Script To Executable With Cx_freeze, Exe Does Nothing"