[Tutor] how do i use p2exe

Dick Moores rdm at rcblue.com
Sun Nov 14 06:20:06 CET 2004


Thanks, Kent. I've gotten to the point where I can create an exe in 
Python23/dist of a script in Python23. For example, from weekday1.py I've 
created weekday1.exe. When I double-click on Python/dist/weekday1.exe, it 
works fine in a consol window. But when I copy weekday1.exe to my 
desktop, all I get is a flash of a console window opening and closing 
when I execute it.

Here's weekday1.py: <http://www.rcblue.com/Python/weekday1.py>
And setup.py: <http://www.rcblue.com/Python/setup.py>

Can you tell me what's wrong?

Thanks,

Dick

Kent Johnson wrote at 19:47 11/13/2004:
>Dick,
>
>The script you are using is an attempt to automate the use of py2exe so 
>you don't have to create setup.py for each script. I suggest you try a 
>manual approach.
>
>I downloaded and installed py2exe. I opened a DOS console to 
>C:\Python23\Lib\site-packages\py2exe\samples\simple and typed
> > python setup.py py2exe
>
>This created a dist directory with two executables - a console program 
>and a wxPython program.
>
>Does this work for you?
>If it does, the next step is to copy setup.py from the samples dir to 
>the dir where your program is, and modify it appropriately. It's a 
>pretty simple file, this isn't be hard.
>
>If you can't get that to work, you might want to ask on the py2exe 
>mailing list, we don't seem to have any experts here.
>
>Kent
>
>Dick Moores wrote:
>>This is my second attempt to get some help. I'd REALLY like to be able 
>>to use py2exe:
>>
>>Am I the only one having trouble with this? Here's what I did, and what 
>>happens.
>>I'm running Win XP and Python 2.3.4.
>>I installed py2exe from http://starship.python.net/crew/theller/py2exe/ .
>>I created setup.py. But in order to have it run I changed the 3rd line 
>>of lookdir() to   if look.lower() == "y":
>>I created the batch file, which I named test.bat. I used the line 
>>cd\python23 as is, because that's where my python23 is.
>>When I run test.bat I get
>>"Current directory is: C:\Python23
>>Do you wish to see what's in directory?"
>>If I answer "y" I'm correctly shown what's in Python23, and asked,
>>"What is the file you want as an executable? (Type 'quit' to break out 
>>of loop) ?"
>>I type "weekday.py" a script I have in Python23.
>>The "DOS" (consol?) window closes immediately.
>>That's it. No creation of weekday.exe.
>>Have I done something wrong. Or what?
>>Thanks, tutors.
>>Dick Moores
>>rdm at rcblue.com
>>
>>At 19:59 11/9/2004, Jacob S. wrote:
>>
>>>This is what I did.
>>>I'm using Windows XP, but it would work for any other windows version...
>>>
>>>1) Take code below and copy into file named "setup.py".
>>>
>>>### Start of Code ###
>>>from distutils.core import setup
>>>import py2exe
>>>import os
>>>
>>>
>>>def lookdir():
>>>     print "Current directory is: %s" % os.getcwd()
>>>     look = raw_input('Do you wish to see what\'s in directory? ')
>>>     if look.lower() in m:
>>>         print "\n".join(os.listdir(os.getcwd()))
>>>
>>>def changedir():
>>>     m = ['y','ye','yes','yep','okay','affirmative','sure']
>>>     ask = 'y'
>>>     lookdir()
>>>     while ask not in m:
>>>         di = raw_input('What directory do you want? ')
>>>         os.chdir(di)
>>>         lookdir()
>>>         ask = raw_input('Do you want this directory? ')
>>>
>>>changedir()
>>>listed = []
>>>while 1:
>>>     ask = raw_input('What is the file you want as an executable? (Type
>>>\'quit\' to break out of loop) ')
>>>     if ask == 'quit' or ask == 'stop' or ask == '':
>>>         break
>>>     else:
>>>         listed.append(os.path.join(desktop,ask))
>>>
>>>setup(console = listed)
>>>### End of Code ###
>>>
>>>2) Take following code and save as a batch file. You will have to 
>>>change the
>>>second line to change the directory to your python dir
>>>
>>>rem Start of Code
>>>@echo off
>>>cd\python23
>>>start python setup.py py2exe
>>>rem End of Code
>>>
>>>3) Run the batch file. It will ask you which directory the script file is
>>>in. That would be the file that you're trying to make and executable. 
>>>Then,
>>>when you decide which directory it is in, it will ask you the name of the
>>>file. You type in the name. If you want more than one file, you can 
>>>type in
>>>another file name in the next prompt, else you can type in 'quit' or 
>>>'stop'
>>>or just hit enter. When all is done and the shell window closes, you can
>>>check out the directory that you chose. In that directory, there will 
>>>be two
>>>new folders. One is labeled build. That folder is not necessary to run 
>>>your
>>>executable and can be deleted. I usually delete it. The other is labeled
>>>dist. It contains the files needed for your program. Your program will 
>>>have
>>>the same name, just with a exe extension instead of a py extension. 
>>>Send the
>>>whole folder on to your students, and they can double-click on the exe 
>>>file,
>>>and it will run your script as if you double-clicked it in Windows 
>>>Explorer.
>>>
>>>Also, in your code (which I will try to rewrite for fun on my own (no
>>>offense)) you might try this instead:
>>>
>>>print "".join(["\t","\\"*7," ","\\"*4," ","\\"*6," ","\\"*7," ","\\"*2,"
>>>","\\"*10," ","\\"*2," ","\\"*8,"\n"])
>>>
>>>Ignore the underline and blue if it shows up in your email thing.
>>>This just shows that you can multiply a particular string by an integer to
>>>copy it.
>>>
>>>Hope all this helps,
>>>Jacob Schmidt
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor at python.org
>>http://mail.python.org/mailman/listinfo/tutor
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor at python.org
>>http://mail.python.org/mailman/listinfo/tutor
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list