Page 1 of 3 123 Last
  • Jump to page:
    #1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    UK
    Posts
    367
    Rep Power
    11

    Thumbs up Just started Python...


    Ok i've written my program. It's called program1.py. Now what should I do for setup.py and then changin 2 an exe with py2exe?Does it matter what folder the files are in?Any help would be much appreciated. thank you.
    Last edited by lucas; January 22nd, 2004 at 09:34 AM.
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Well i dunno what your program looks like but best case all you need in your setup.py file is...

    Code:
    from distutils.core import setup
    import py2exe
          
    setup(console=["myscript.py"])
    Take a look at the distutils.core.setup in the Python docs for more info:

    http://www.python.org/doc/current/di...up-script.html

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    UK
    Posts
    367
    Rep Power
    11
    Ok tnx, but what would I do to run setup and where should the files be placed?Whenerver I type stuuf in the command, e.g. setup.py py2exe i get told that there is a syntax error: invalid syntax
    Last edited by lucas; January 22nd, 2004 at 10:26 AM.
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Ah ok, does your program actually run before you try and compile with py2exe? Anyway the command line should look like this

    python path/to/setup.py py2exe

    After this you should have an .exe placed somewhere on your Python Path, i believe in the py2exe directory but i'm not 100%..

    you can put you're files where you like . Another link you might be interested in:

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

    Mark.
    programming language development: www.netytan.com Hula

  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    UK
    Posts
    367
    Rep Power
    11
    It does run b4 i compile in py2exe, but im stil gettin a syntax error. What actually is syntax?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    netherlands
    Posts
    51
    Rep Power
    11
    I actually always used this:

    (python path)/python setup.py py2exe

    I think your exe file is in the folder dist now. If not you have to check the folders somewhere in ti you'll find a folder named your program. it's in there
  12. #7
  13. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Mmmm ok, whats the best way to explain syntax... i guess, and sorry if this is hard to understand.

    Syntax is like a set of rules you must obay when writing in a given language. Like grammer in english. Sentences begin with capitals and end in full strops.

    A syntax error is generated when your code breaks the rules for whatever reason.

    Hope that helps... so have you got it working now? If not can you attach the files your using. Might make it easier to track down the problem.

    Mark.
    programming language development: www.netytan.com Hula

  14. #8
  15. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    UK
    Posts
    367
    Rep Power
    11
    <u>I think I got the setup script rite cos in turned the files into compiled python files, but I still havnt managed to change it into a .exe The code for the program1.py file is:</u>

    Code:
    a = ("Dan")
    print "Halt!"
    s = raw_input("Who goes there? ")
    if s != a:
        print s,", get off this computer!"
    if s == a: 
        print "You may pass,", s
    d = raw_input("Where would you like to go?")
    print "then go to" ,d, s
    
    password = "foobar"
    
    #note that != means not equal
    while password != "learn":
        password = raw_input("Password:")
    print "You have gained access to this program."
    number = 56
    guess = 0
    
    while guess != number : 
        guess = input ("Guess a number: ")
    
        if guess > number :
            print "Too high"
    
        elif guess < number :
                print "Too low"
    
    print "Just right"
    <u>and the setup script is:</U>

    Code:
    #!/usr/bin/env python
    
    from program1 import setup
    import py2exe
    
    setup(name="program1",
          version="1.0",
          description="Python Distribution Utilities",
          author="LuCaS",
          author_email="???@???.???",
          url="http://www.python.org/sigs/distutils-sig/",
         )
    <u>Thanx 4 all ur help. I rly appreciate it!</u>
    Last edited by netytan; January 23rd, 2004 at 09:17 AM.
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    UK
    Posts
    367
    Rep Power
    11
    I got another question as well. Say i wanted to write a program that downloads a text file off a website automatically whn it is opened and then displays it. How could I go about this?
  18. #10
  19. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    OK, lets take another guess .. i'm thinking the last error you got was because setup.py isnt being found soooooo give this a go lol

    C:\Python23\python path\to\setup.py py2exe -d C:\

    That should fix the <stdin> bit... if not i'm running outa ideas

    Mark.
    programming language development: www.netytan.com Hula

  20. #11
  21. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Ok, lets take another stab at this , try this one...

    C:\Python23\python path\to\setup.py py2exe -d C:\

    The <stdin> bit seems to be because setup.py couldn't be found... at the least that should be fixed *crosses fingers*

    Mark.
    programming language development: www.netytan.com Hula

  22. #12
  23. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    A big part of whats wrong here could be the first line in your setup.py file . Just tried compiling your program myself and it ran without any problems... soooo.

    Code:
    setup.py
    from distutils.core import setup
    import py2exe
          
    setup(console=["program1.py"])
    Give that a go...

    Mmm, what exactly do you want it to do? Just download a text file at a given URL weh the program is run?

    Mark.
    programming language development: www.netytan.com Hula

  24. #13
  25. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    UK
    Posts
    367
    Rep Power
    11
    Pretty much, yeh, and then display it in it's window. Il jus c if ur setup script helped...
  26. #14
  27. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    UK
    Posts
    367
    Rep Power
    11
    Ok i tryed that script and ran it in the shell to see what happened and this was the error i got:


    Traceback (most recent call last):
    File "C:\Python23\setup.py", line 1, in -toplevel-
    setup.py
    NameError: name 'setup' is not defined

    the path to python/ where the .py files are is C:\Python23
  28. #15
  29. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Ok very basic example here but it does work ..

    what this does is: import the os and urllib modules. read the url and put it into 'txt' then just write this to a file and open it in notepad.

    Code:
    #!/usr/bin/env python
    
    import os, urllib
    
    url = 'http://somwhere.com/txt'
    txt = urllib.urlopen(url).read()
    
    file('rundown.txt', 'w').write(txt)
    
    os.system('rundown.txt')
    Mark.
    programming language development: www.netytan.com Hula

Page 1 of 3 123 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo