2

I have 2 python scripts inside my c:\Python32 1)Tima_guess.py which looks like this:

#Author:Roshan Mehta
#Date  :9th October 2012

import random,time,sys
ghost ='''
0000 0 000----
00000-----0-0
----0000---0
'''

guess_taken = 0

print('Hello! What is your name?')
name = input()
light_switch = random.randint(1,12)
print("Well, " + name + ", There are 12 switches and one of them turns on the Light.\nYou just need to guess which one is it in 4 guesses.Purely a luck,but i will help you to choose")
print("Choose a switch,they are marked with numbers from 1-12.\nEnter the switch no.") 
while guess_taken < 4:

    try:
        guess = input()
        guess = int(guess)
    except: 
        print("invalid literal,Plese enter an integer next time.")
        x = input()
        sys.exit(1)


    guess_taken = guess_taken + 1
    guess_remain = 4 - guess_taken
    time.sleep(1)

    if guess < light_switch:        
        print("The Light's switch is on right of your current choice.You have {} more chances to turn on the light.".format(guess_remain)) 

    if guess > light_switch:
        print("The Light's switch is on left of your current choice.You have {} more chances to turn on the light.".format(guess_remain))

    if guess == light_switch:
        print("Good,you are quiet lucky,You have turned on the light in {} chances.".format(guess_taken))
        sys.exit(1)

if guess != light_switch:
    print("Naah,You don't seems to be lucky enough,The switch was {}.".format(light_switch))
    for i in range(3):
        time.sleep(2)
        print(ghost)
    print("The Devil in the room has just killed you....Ha ha ha")

input()

2)setup.py which look like this:

from cx_Freeze import setup, Executable
setup(
    name = "Console game",
    version = "0.1",
    description = "Nothing!",
    executables = [Executable("Tima_guess.py")])

When i run python setup.py build it creates an executable in build directory inside c:\Python32\build but when i run Tima_guess.exe it just shows a black screen and goes off instantly not even able to see the message it is throwing. Please help me to get a standalone executable of my Tima_guess.py game.

Regards.

As according to Thomas suggestion when i explicitly go and run in the cmd by Tima_guess.exe.I get the following error but still not able to make out what is wrong.

c:\Python32\build\exe.win32-3.2>Tima_guess.exe
Traceback (most recent call last):
  File "c:\Python32\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 2
7, in <module>
    exec(code, m.__dict__)
  File "Tima_guess.py", line 4, in <module>
  File "c:\Python32\lib\random.py", line 39, in <module>
    from warnings import warn as _warn
  File "C:\Python\32-bit\3.2\lib\warnings.py", line 6, in <module>
  File "C:\Python\32-bit\3.2\lib\linecache.py", line 10, in <module>
  File "C:\Python\32-bit\3.2\lib\tokenize.py", line 28, in <module>
ImportError: No module named re

c:\Python32\build\exe.win32-3.2>
6
  • Can you try running Tima_guess.exe in a command prompt so you can see the error message it produces? Commented Oct 9, 2012 at 20:39
  • Yes,it just runs and goes off...Not able to see anything.If i just run Tima_guess.py in IDLE.It works perfectly but i want the standalone .exe which i can distribute to my friends. Commented Oct 10, 2012 at 7:34
  • If you go to the folder in a command prompt and type Tima_guess.exe, you should be able to run it so that it doesn't disappear straight away, and you can see the error message. You need to see the error message to work out what's wrong. Commented Oct 10, 2012 at 22:34
  • Thanks Thomas...But still I'm not able to figure out the problem.please help me out. Commented Oct 11, 2012 at 3:52
  • OK, I think you just need to specify that it should include re. Have a look at the example setup.py here: cx_freeze.readthedocs.org/en/latest/distutils.html Commented Oct 13, 2012 at 10:00

2 Answers 2

2

After building, add re.pyc to the library.zip file.
To get re.pyc, all you need to do is run re.py successfully, then open __pycache__ folder, then you will see a file like re.cpython-32.pyc, rename it to re.pyc and voila!

Sign up to request clarification or add additional context in comments.

Comments

1

setup.py

from cx_Freeze import setup, Executable

build_exe_options = {"includes": ["re"]}

setup(
        name = "Console game",
        version = "0.1",
        description = "Nothing!",
        options = {"build_exe": build_exe_options},
        executables = [Executable("Tima_guess.py")])

1 Comment

Guys i have added this line to my setup.py but still i'm getting the same error,If possible try making Tima_guess executable in your system and let me know whether it's working or not? build_exe_options = {"includes": ["re"]}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.