0

So I've been playing around with Python and testing it on other computers by using cx-freeze to turn my Python script into an exe.

Recently I learned how to use the Turtle module and used it in my script. I tested it my script and it worked perfectly but when I turned it into an executable it doesn't open.

# TURTLE TEST
import time
from turtle import *
pen1 = Pen()
title('ILLUMINATI')

pen1.screen.bgcolor('#FFFFFF')

pen1.color('#000000')
pen1.up()
pen1.goto(-100, 200)
pen1.down()
pen1.begin_fill()
for i in range(3):
    pen1.fd(200)
    pen1.left(360/3)
pen1.end_fill()
pen1.up()
pen1.goto(0, -100)
write("ILLUMINATI", False, align='center',font=('Times', 50, 'bold'))
done()
matsjoyce
  • 5,744
  • 6
  • 31
  • 38
  • 1
    What does your code look like? How did you setup and call cx-freeze? What output did cx-freeze produce when it was compiling the script? Right now, it's difficult to say what the problem is since it could be anything. (To add more information to your post, click "edit" in the lower-left.) – Michael0x2a Sep 14 '14 at 17:22
  • @Michael0x2a it had no issues when building but when i tested the exe a command prompt came up and went away. I tried to see what the issue is and I think it's the turtle module. i ran this short script using turtle – Fabrizio Torres Sep 14 '14 at 19:12
  • 1
    Try running the exe from a command prompt, and the error should stick around long enough to read it. – Thomas K Sep 15 '14 at 00:44

2 Answers2

0

To see what is going on, wrap your entire code as follows:

try:
    <your code>
except BaseException:
    import sys, traceback
    traceback.print_exc(file=sys.stderr)
    input"dummy propmt")

This assumes that sys.stderr is connected to the console window you saw (it might not be). The input statement should keep the process alive and the window visible. If not, open and print to a disk file (and delete input()) or see my answer to another question for how to display in a tkinter window. For the latter, you may need root.mainloop() to keep the process alive.

Community
  • 1
  • 1
Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
0

I wrote a setup.py as follows:

from cx_Freeze import setup, Executable

setup(version="1.0",
      executables=[Executable(script="turtle_test.py",
                              base="Win32GUI",          
                              targetName="turtle_test.exe",
                              )]
      )

Then I ran it this way: c:\Python34\python.exe setup.py build

Executable works fine for me, just remember that you have to keep all the files and directories with dependencies:

tcl\
tk\
_bz2.pyd
_ctypes.pyd
_tkinter.pyd
library.zip
python34.dll
tcl86t.dll
tk86t.dll
turtle_test.exe
unicodedata.pyd

My Python, OS and library versions are:

OS: Windows-7-6.1.7601-SP1 (32bit)
Python: 3.4.1
cx_Freeze: 4.3.3
Fenikso
  • 9,251
  • 5
  • 44
  • 72