[Tutor] how do i use p2exe

Jacob S. keridee at jayco.net
Sun Nov 14 17:45:32 CET 2004


I see what's wrong with my code. First, to Kent, what's wrong with trying to
automate py2exe? It drives me batty to have to open the command prompt in
Windows and then go to the python23 folder and type in "python setup.py
py2exe" which I can't remember when I need it. Then, I always have to change
setup.py every time I want to use py2exe. I think that if you can get it to
work, automation would be beautiful. (It works on my machine.)
    Second, to Dick.
There are one or two things wrong with the code I gave you. It was late.
However, you did not use the raw_inputs quite as I would have expected. So,
a detailed run through.

First, change my setup.py to read as follows:

##Start of code
### Start of Code ###
from distutils.core import setup
import py2exe
import os

def lookdir():
    m = ['y','ye','yes','yep','okay','affirmative','sure']
    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']
    ## Here I have to define m again because of local variables. Ughh.
    ask = raw_input('Do you want the current directory? ')  ## Had to fix
this, brain fart.
    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 ###

Okay, the batch file should be okay...
But just in case...

rem Start of Code
@echo off
cd\python23  rem Change this line to your python directory
start python setup.py py2exe
rem End of Code

I made a couple of changes to the code above.
Okay, a complete walkthrough.

1) Copy setup.py code to file in python directory
2) Copy batch file code to any convenient directory.
3) Run batch file
4) You should get a python console program.
5) Okay the nitty-gritty, cross your fingers, hope I have it right this
6) It should show current directory, ask you if you want to see what's in it
7) It should ask you whether you want the current dir
8) If you say no, then it will ask you for a new directory. It will run
through steps 6-8
    until you say that you want the current directory
9) It will ask you what file you want until you type in quit. This is for
multiple file executables.
    Each thing you type in other than quit will be thought of as a file in
the current directory.
     ''        ''        ''    ''    ''    ''        ''    ''      ''    ''
put in the executable directory.
10) When you type quit in step 9, it will make executables for every other
thing you typed in.
11) Python console should disappear.
12) In the directory that the files are in, you should have two folders,
build and dist.
13) Dist is the folder that you are looking for, build is another helper
folder that doesn't really do         anything as far as I can tell. It can
be deleted.
14) Run each executable in the dist folder. The ones that have the same
names as the files you             typed in should all work. (There is
another executable in there that doesn't stand alone. It's part     of the
15) You can rename the dist folder anything you want.
16) You have to leave everything in the dist folder intact.
17) You should probably put shortcuts to the programs in a more convenient
18) That should be it. If it doesn't work now, I should be very unhappy and
I would like to know     why it doesn't work!

I hope this will help someone,
Jacob Schmidt

More information about the Tutor mailing list