New OOTS products from CafePress
New OOTS t-shirts, ornaments, mugs, bags, and more
Results 1 to 12 of 12
  1. - Top - End - #1
    Ogre in the Playground
     
    Flumph

    Join Date
    Sep 2013

    Default Trying to Learn Python: Problems running Python Scripts

    Hello,

    I am trying to learn the basics of using Python (version 2.7) using Google's free course (link to the overview). If you check out the set up, they talk about a script "hello.py" to run to see if things are installed properly.

    I can pull up python on my computer and use it for basic commands, such as setting values and do math with those values, but I cannot get it to find the hello.py script on my computer when I type "python hello.py" into Python.

    Any ideas where I have made an error?

    Thanks for the assistance!

  2. - Top - End - #2
    Titan in the Playground
     
    Jasdoif's Avatar

    Join Date
    Mar 2007
    Location
    Oregon, USA

    Default Re: Trying to Learn Python: Problems running Python Scripts

    Quote Originally Posted by Mith View Post
    I am trying to learn the basics of using Python (version 2.7) using Google's free course (link to the overview). If you check out the set up, they talk about a script "hello.py" to run to see if things are installed properly.

    I can pull up python on my computer and use it for basic commands, such as setting values and do math with those values, but I cannot get it to find the hello.py script on my computer when I type "python hello.py" into Python.

    Any ideas where I have made an error?
    You'd type "python hello.py" into a system command prompt, not into Python itself. That's what the "open a command line" bit in the Python Set Up section is trying to tell you.
    Feytouched Banana eldritch disciple avatar by...me!

    The Index of the Giant's Comments VI―Making Dogma from Zapped Bananas

  3. - Top - End - #3
    Ogre in the Playground
     
    Flumph

    Join Date
    Sep 2013

    Default Re: Trying to Learn Python: Problems running Python Scripts

    Quote Originally Posted by Jasdoif View Post
    You'd type "python hello.py" into a system command prompt, not into Python itself. That's what the "open a command line" bit in the Python Set Up section is trying to tell you.
    WHen I do that, I get the following:

    "python: can't open file "hello.py" ..."No such file or directory"

    But I have the file "hello.py" in a Documents folder on my computer. Should I be moving this to a different location for Python to find it?

  4. - Top - End - #4
    Titan in the Playground
     
    Jasdoif's Avatar

    Join Date
    Mar 2007
    Location
    Oregon, USA

    Default Re: Trying to Learn Python: Problems running Python Scripts

    Quote Originally Posted by Mith View Post
    WHen I do that, I get the following:

    "python: can't open file "hello.py" ..."No such file or directory"

    But I have the file "hello.py" in a Documents folder on my computer. Should I be moving this to a different location for Python to find it?
    Well, you could move the file and/or change where the command prompt is running programs from; as long as it's the same place, it should work. A thorough walkthrough of command prompt navigation is...too much for me to provide here.

    However, since I'm lazy and I see the Google page gives you an entire zipped folder of their Python exercises....What I'd do, assuming you're running Windows, is copy the one "google-python-exercises" folder in their zip file (the folder itself, not just the files in it) to the top of the drive; so you'd have a new "google-python-exercises" folder there. Then when you open the command prompt, you should be able to do
    Code:
    cd \google-python-exercises
    to change the directory the command prompt's running from to that folder, and then "python hello.py" should be able to find the file it's looking for.
    Last edited by Jasdoif; 2017-12-09 at 12:02 AM.
    Feytouched Banana eldritch disciple avatar by...me!

    The Index of the Giant's Comments VI―Making Dogma from Zapped Bananas

  5. - Top - End - #5
    Bugbear in the Playground
    Join Date
    Sep 2014

    Default Re: Trying to Learn Python: Problems running Python Scripts

    You can also drag and drop a file from "Windows Explorer" into the command line and it'll give the full path to that file. You could type "python" and then instead of typing hello.py open up Windows Explorer, find your hello.py file wherever you saved it and "drag" it into the command line. You should get something like python "C:\Users\Mith\Documents\hello.py" when you do that.

  6. - Top - End - #6
    Ogre in the Playground
     
    Flumph

    Join Date
    Sep 2013

    Default Re: Trying to Learn Python: Problems running Python Scripts

    Quote Originally Posted by Jasdoif View Post
    Well, you could move the file and/or change where the command prompt is running programs from; as long as it's the same place, it should work. A thorough walkthrough of command prompt navigation is...too much for me to provide here.

    However, since I'm lazy and I see the Google page gives you an entire zipped folder of their Python exercises....What I'd do, assuming you're running Windows, is copy the one "google-python-exercises" folder in their zip file (the folder itself, not just the files in it) to the top of the drive; so you'd have a new "google-python-exercises" folder there. Then when you open the command prompt, you should be able to do
    Code:
    cd \google-python-exercises
    to change the directory the command prompt's running from to that folder, and then "python hello.py" should be able to find the file it's looking for.
    Thank you for your response. I apologise for the silly question. I am thinking the problem is that I am working on the ground floor without a foundation, so to speak. I had the files stored to be in a folder that the initial directory (so the path using the central filing system was (C:)>Users>Mith>google-python-exercises. My reasoning was that "(C:)>Users>Mith>" is where the directory already was when starting the command window. The file and program will just be extended from there.

    From what I can gather now that I can get things to work, it needs to be (C:)>google-python-exercises.

    If this comes across as incorrect, it's because I written things poorly, since I at least got things working.

    Once again, thank you for your assistance. I apologise for any headaches I may have caused.

  7. - Top - End - #7
    Troll in the Playground
     
    Imp

    Join Date
    Jul 2008
    Location
    Sweden
    Gender
    Male

    Default Re: Trying to Learn Python: Problems running Python Scripts

    A quick and easy way to get to the correct directory is hold shift and left click inside the directory. An extra option of "open command line here" (or "open powershell here") will appear that will automatically be in the correct folder.
    Black text is for sarcasm, also sincerity. You'll just have to read between the lines and infer from context like an animal

  8. - Top - End - #8
    Bugbear in the Playground
    Join Date
    Mar 2007

    Default Re: Trying to Learn Python: Problems running Python Scripts

    Does your python come with Idle? If so it is probably easier to edit with Idle and simply hit [F5] to run your script.

    There must be better python IDEs out there, but I got used to IDLE and still use it (it is *extremely* primitive as an IDE, but I just like primitive tools. And it generally won't get in your way while learning python (you don't waste time figuring out if you issue is with your program or your tool usage).

    It might also be better to start with python 3 as the python world might finally be going that way. It isn't *that* big a deal (mostly in how printing is handled, and remembering that you don't have to bother with "xrange"). Since pypy (and plenty of other projects) are still on 2 it isn't a big deal but I suspect that you might be picking up old habits.

  9. - Top - End - #9
    Ogre in the Playground
     
    Lacuna Caster's Avatar

    Join Date
    Oct 2014

    Default Re: Trying to Learn Python: Problems running Python Scripts

    Quote Originally Posted by Mith View Post
    From what I can gather now that I can get things to work, it needs to be (C:)>google-python-exercises.
    There's a basic primer on console commands here, but just remembering 'cd' and 'dir' will get you a long way.

    I'd recommend using PyDev with Eclipse, but if you're still figuring out the command-line that might be a little complicated?
    Give directly to the extreme poor.

  10. - Top - End - #10
    Ogre in the Playground
     
    Flumph

    Join Date
    Sep 2013

    Default Re: Trying to Learn Python: Problems running Python Scripts

    Quote Originally Posted by wumpus View Post
    Does your python come with Idle? If so it is probably easier to edit with Idle and simply hit [F5] to run your script.

    There must be better python IDEs out there, but I got used to IDLE and still use it (it is *extremely* primitive as an IDE, but I just like primitive tools. And it generally won't get in your way while learning python (you don't waste time figuring out if you issue is with your program or your tool usage).

    It might also be better to start with python 3 as the python world might finally be going that way. It isn't *that* big a deal (mostly in how printing is handled, and remembering that you don't have to bother with "xrange"). Since pypy (and plenty of other projects) are still on 2 it isn't a big deal but I suspect that you might be picking up old habits.
    The free course I'm using as an introduction was developed for lat python 2, so I figure I should start there. And I do have access to IDLE.

  11. - Top - End - #11
    Ogre in the Playground
     
    Flumph

    Join Date
    Sep 2013

    Default Re: Trying to Learn Python: Problems running Python Scripts

    Quote Originally Posted by Mastikator View Post
    A quick and easy way to get to the correct directory is hold shift and left click inside the directory. An extra option of "open command line here" (or "open powershell here") will appear that will automatically be in the correct folder.
    Good to know!

  12. - Top - End - #12
    Ogre in the Playground
     
    ElfPirate

    Join Date
    Aug 2013

    Default Re: Trying to Learn Python: Problems running Python Scripts

    back in ye olden days you would have to add the python fodler to the "system environment" variable. Thus you could access the python executible from where ever you happened to be. Not sure how this is done anymore. Hopefully the installation did it for you.

    But your problem is basically the same as back when. The python file you are calling is not in the place it's looking because it's only looking in the folder you are currently in.

    If you don't have python registered to be able to run from everywhere you'll have the opposite problem trying to run said file from the folder it resides in.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •