Results 1 to 8 of 8
  1. - Top - End - #1
    Bugbear in the Playground
     
    GnomeWizardGuy

    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
    Ettin 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.

  3. - Top - End - #3
    Bugbear in the Playground
     
    GnomeWizardGuy

    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
    Ettin 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; Yesterday at 12:02 AM.

  5. - Top - End - #5
    Orc 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
    Bugbear in the Playground
     
    GnomeWizardGuy

    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
    Ogre 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.
    Yar! I'm a signature virus, copy me into your signature!

    Black text is for sarcasm, also sincerity. You'll just have to read between the lines and infer from context, like a savage

  8. - Top - End - #8
    Barbarian 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.

Posting Permissions

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