11

I recently created used cx_freeze to create a python 3.2.2 exe file. When I tried to run the exe file nothing happened.

Here is the code for my test.py file:

print("hello world")

for i in range(5):
    print(i)

Here is the code for my testSetup.py file:

from cx_Freeze import setup, Executable

exe = Executable(
   script="test.py",
   base="Win32GUI",
   targetName="Test.exe"
   )


setup(
    name = "Test",
    version = "0.1",
    description = "I wish programming was this easy",
    executables = [exe])

The build directory that cx_freeze made has a folder called exe.win32-3.2 which has the files:

bz2.pyd
library.zip
python32.dll
Test.exe
unicodedata.pyd

Snake P
  • 111
  • 1
  • 1
  • 5

2 Answers2

21

My suggestion:

  1. set base = None (try it: maybe that's all you want? base = Win32GUI does "hide" the console - this is useful when you're building a GUI)

  2. In the same folder with your .exe make a batch-file (a text-file with .bat) calling your .exe:

this goes into your batch-file:

name-of-your-app.exe %1

PAUSE

You'll start your app by clicking the batch-file - it keeps the console open so you're able to reed the errors/output.

Chrugel
  • 883
  • 2
  • 11
  • 19
4

Place a input() at the bottom of your code, and try again:

Looks like your .exe runs and exists before you can see anything, so place a input() at the bottom to make the script wait for user input before exiting.

print("hello world")

for i in range(5):
    print(i)
input()
Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504
  • 2
    I put input() at the bottom of my code and ran it, but then an error popped up that said: Cannot import traceback module. Exception: No module named re Original Exception: input(): lost sys.stdin – Snake P Oct 09 '12 at 01:42
  • @AshiwiniChuadhary I did what the link said to do, but then it threw an error because of input. So then I removed the input line and it's back to doing nothing or the command prompt is disappearing too fast to see it. – Snake P Oct 09 '12 at 02:13
  • @SnakeP that's weird, try running the .exe through cmd itself try with `input()` removed. – Ashwini Chaudhary Oct 09 '12 at 02:16
  • @AshiwiniChuadhary I tried it in the cmd itself and with input() it still threw an error and without it, it didn't print anything. – Snake P Oct 09 '12 at 02:18
  • @AshiwiniChuadhary the error it threw said: Traceback(most recent call last): File "C:\Python32\lib\site-packages\cx_Freeze\initscripts\Console3.py",line27,inexec(code,m._dict_)File"test.py",line 7, inRuntimeError:input():lost sys.stdin – Snake P Oct 09 '12 at 02:24