[Tutor] how do i use p2exe
kent37 at tds.net
Sun Nov 14 04:47:21 CET 2004
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
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.
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
> 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'
>> while ask not in m:
>> di = raw_input('What directory do you want? ')
>> ask = raw_input('Do you want this directory? ')
>> 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 == '':
>> 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
>> 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.
>> 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
>> 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
>> 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
>> 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
>> and it will run your script as if you double-clicked it in Windows
>> 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
> Tutor maillist - Tutor at python.org
More information about the Tutor