Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    3
    Rep Power
    0

    Another py2exe in Windows question


    *Smile* Hello!

    Brand new to both Python and py2exe.

    I'm running Windows '98 on this computer. I realized I needed the Microsoft Layer for Unicode - I downloaded, I installed. That's not the issue.

    Searching on Google I found the "How to convert .py to .exe?" thread here. (http://forums.devshed.com/archive/t-91836) Used the advice. Made the setup script just as the person there showed, except mine was add and add.py instead of abc. This is all in my Python23 folder in the programs file.

    Then I ran c:\python23\python.exe setup.py py2exe, and the Python shell came out and a bunch of things ran down the screen, just as it should. No errors.

    Problem is, the exe file still doesn't exist. Looked everywhere in the Python23 folder, and nope. Even ran a "find file" on "add.exe", and it doesn't exist.

    Same thing happened when I tried with makeExe.py:
    http://aspn.activestate.com/ASPN/Coo.../Recipe/266471

    I followed the directions to a "t", ran it, and it told me the .exe file had been created. Yet it doesn't exist...!

    I'm thoroughly confused now. Tried the "find related threads" option here, but no one else seems to have had the same problem.

    If anyone has any ideas (or knows of another converter that may work better for me), I'd be greatly indebted!

    Thanks,
    mellee
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    the latest version of py2exe (0.5) is very different to the older versions. Try the instructions on the py2exe website and py2exe wiki.

    If things run correctly then you should have a new sub-directory called "dist", this contains the executable and other files you need. The executable is only about 24 kbytes - all the python files will be in a zip. The sub-directory is created in the directory containing your python file.

    Good luck,
    Grim
    Last edited by Grim Archon; April 8th, 2004 at 02:54 PM.
  4. #3
  5. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    The following script will create an executable, hopefully it's comments explain the code...
    Code:
    #####################
    # win_exe.py
    #####################
    # This basic script creates a windows executable.
    # Requires py2exe 0.5 has been installed matching your python version.
    # This program should be placed in the directory containing the python script you want to compile.
    #
    # Edit this file, replacing references to "myfile" with your script's name.
    #
    # Either run this program from IDLE (F5) or double click it to create an executable.
    # Run it from IDLE to see the normal output and check for errors.
    #
    # The executable and all required support files will be created in the "dist" sub-directory
    # This program is for making Windows (not comand line) programs.
    # see http://starship.python.net/crew/theller/py2exe/ for more details.
    
    from distutils.core import setup
    import py2exe
    import sys
    import glob
    
    
    sys.argv.append("py2exe") #Avoids having to use the command line
    
    setup(
        name = "myfile", 
        #Define the windows executable....
        windows = [
                    {
                        "script": "myfile.pyw",  #the name of the python script - must be a *pyw* file
                        "icon_resources": [(1, "myfile.ico")] #include this application icon - optional
                    }
                    ], 
        #Optional stuff - the following bundles data files with the executable - edit as required
        data_files = [
                        (".", ["readme.txt", "setup.py"]),  #example - include these files from the current directory
                        (".", glob.glob("*.html")),  #example - include all html files from the list of files created by glob 
                           
                    ], 
        #End of optional stuff
        )
    Grim
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    3
    Rep Power
    0
    Thank you.

    The funny thing is I tried the py2exe and that other script on my laptop - running XP - now, too. The very same things happened. This has gotta be something I'm doing wrong, right?

    The dist file is there, and inside are the _sre, the zip, the w9popen.exe, and the python23.dll. No executable. I even opened the zip - not in there. Again, did a search for add.exe on the system and it also tells me it doesn't exist.

    The script above - I ran it and wonder of wonders an executable created in the file! However it only works on a .pyw. My scripts are things that need the dos window. When I open the exe into notepad, the only thing I can read on it is "This program cannot be run in DOS mode." Tried just putting in a .py anyway, but no dice. The exe won't execute.

    Judging from the fact that I found this, it doesn't seem the exe created on the others and I'm just not finding it...
    Last edited by mellee; April 8th, 2004 at 04:49 PM. Reason: (Rude enough that I forgot to say "Thank you".
  8. #5
  9. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    To make a console version is very easy:

    replace the word windows with console.

    Grim
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    3
    Rep Power
    0
    YYYAAAAAAAYYYYYYY!!!!!!!!!!!!!! Thank you so veryvery much, Grim! It worked!!!
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    Well I don't get it does it ave to be pasted infront or back of the acual script
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    Okay could someone please make an exe out of this and put the script up here ok

    while 1:
    k= raw_input("If a tree falls in the forest and nobody hears it. Does it make a sound? Answer yes or no.")

    if k== "no":
    print "How do you know because what if it does just nobody hears it."

    a= raw_input("Do you want to try again. yes or no.")

    if a== "yes":
    print "Okay here is your try."

    if a== "no":
    print "Fine with me just think a little."

    if k== "yes":
    print "How do you know nobody heard it."

    a= raw_input("Do you want to try again. yes or no.")

    if a== "yes":
    print "Okay here is your try."

    t= raw_input("Okay try again. yes or no")

    if t== "yes":
    print "How do you know nobody heard it."

    if t== "no":
    print "How do you know because what if it does just nobody hears it."

    if a== "no":
    print "Fine with me just think a little."


    I made it with an other script but it did not make any file like it made dist and build as a file directory then it went father in build to bdist.win32 and then winexe and in that collect and temp but none of tehm had any files in them

    wats wrong
  16. #9
  17. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Originally Posted by monkeyman23555
    Well I don't get it does it ave to be pasted infront or back of the acual script
    The absolute minimum you need is two files - your script and the one of the following setup.py scripts:

    For a console application (one that allows input and output using the print and raw_input function):
    Code:
    from distutils.core import setup
    import py2exe
    import sys
    sys.argv.append("py2exe")
    setup(console = [{"script": 'prog.py'}])
    If you want a "pure" windows application perhaps using Tkinter or wxPython:
    Code:
    from distutils.core import setup
    import py2exe
    import sys
    sys.argv.append("py2exe")
    setup(windows = [{"script": 'prog.py'}])
    Copy either of these scripts to the directory containing the program you want to "compile", saving it as "setup.py". You will need to replace the name "prog.py" in the above scripts with the name of your script.

    To compile open a DOS box and cd to the directory containing the the scripts and then type the following:
    c:\python23\python setup.py
    or if you are browsing using Windows you can double click the setup.py file to run it - creating your executeable. (Caution: You will miss printed errors if your double click to run.)


    grim
  18. #10
  19. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    If you program has errors then py2exe cannot compile it.

    Run your program using the command line with the python interpreter - that will show you the errors.
    Open a DOS box and CD to the directory containing you program then ....
    Type:
    c:\python23\python nameofyourprogram.py

    Fix all errors first and when you are certain your program works then try py2exe. Don't bother to use py2exe until it works.

    grim
  20. #11
  21. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Code tags are very useful.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    well now i have to .py files in that directory and they are called Tree Fall.py and setup.py

    wat do i do now

    please lead me through this its so confusing
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    35
    Rep Power
    10
    for python 2.4 you need a beta version of the py2exe program, not the standard one
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    40
    Rep Power
    10
    an .exe converted by py2exe can run in a window service code?
  28. #15
  29. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    ah,
    If you mean - can you write Windows services in Python? The answer is yes. The py2exe website explains how this is done.

    http://starship.python.net/crew/theller/py2exe/

    grim
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo