[Tutor] how do i use p2exe

Dick Moores rdm at rcblue.com
Mon Nov 15 00:45:25 CET 2004


Thanks, Kent. That was dumb of me. Yeah, when I copy the dist folder to 
my desktop, weekday1.exe runs fine. So now I assume I could email the 
whole folder to a friend running Win98 (but with no Python), and he could 
use weekday1.exe. That's what I wanted. Thanks for sticking with me.

Dick

Kent Johnson wrote at 03:58 11/14/2004:
>Ah. py2exe doesn't actually create a single-file executable. You need 
>everything else in the dist folder to go with the .exe.
>
>If you want a single file exe, Google for 'py2exe single file' to find 
>some discussions.
>
>If you want the exe on your desktop, just make a shortcut.
>
>A more general tip - when a console-based program is failing, if you run 
>it by double-clicking the exe you will often see just the flash of the 
>console opening and closing. You can get more information by opening a 
>console yourself to the directory and running the exe from the command line.
>
>With weekday1.exe, if I copy it to a new directory and run it from the 
>command line I get this:
>D:\Personal\Tutor\weekday>weekday1
>Traceback (most recent call last):
>   File "C:\Python23\lib\site-packages\py2exe\boot_common.py", line 69, in ?
>     import linecache
>ImportError: No module named linecache
>Traceback (most recent call last):
>   File "weekday1.py", line 8, in ?
>     import datetime
>ImportError: No module named datetime
>
>which might not have been enough for you to figure out the problem but 
>it is at least a clue in the right direction.
>
>Kent
>
>
>Dick Moores wrote:
>>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
>>
>>_______________________________________________
>>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