David Bloom
David Bloom

Reputation: 15

Unable to Run .py script in command prompt

I know this is a super simple problem, but none of the other articles I have looked at have helped. I'm trying to run a hello.py file from command prompt and it is giving me this error message.

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.
C:\Users\Davidjb7>py hello.py
C:\Users\Davidjb7\AppData\Local\Programs\Python\Python36-32\python.exe: can't open file 'hello.py': [Errno 2] No such file or directory

I really don't know why it is though, because hello.py is within the directory Python36-32, as shown here.

C:\Users\Davidjb7\AppData\Local\Programs\Python\Python36-32>dir


Volume in drive C is Windows8_OS
 Volume Serial Number is DC59-907F

 Directory of C:\Users\Davidjb7\AppData\Local\Programs\Python\Python36-32

03/09/2017  04:06 PM    <DIR>          .
03/09/2017  04:06 PM    <DIR>          ..
02/26/2017  10:14 AM    <DIR>          DLLs
02/26/2017  10:14 AM    <DIR>          Doc
03/09/2017  04:05 PM             1,021 hello.py
02/26/2017  10:14 AM    <DIR>          include
02/26/2017  10:14 AM    <DIR>          Lib
02/26/2017  10:14 AM    <DIR>          libs
12/23/2016  07:25 AM            30,049 LICENSE.txt
12/23/2016  07:10 AM           258,657 NEWS.txt
03/09/2017  04:06 PM    <DIR>          python
12/23/2016  07:21 AM            97,944 python.exe
12/23/2016  07:19 AM            52,888 python3.dll
12/23/2016  07:18 AM         3,258,008 python36.dll
12/23/2016  07:22 AM            96,408 pythonw.exe
12/23/2016  07:10 AM             8,434 README.txt
02/26/2017  10:15 AM    <DIR>          Scripts
02/26/2017  10:14 AM    <DIR>          tcl
02/26/2017  10:14 AM    <DIR>          Tools
06/09/2016  10:46 PM            83,784 vcruntime140.dll
               9 File(s)      3,887,193 bytes
              11 Dir(s)  49,034,211,328 bytes free

C:\Users\Davidjb7\AppData\Local\Programs\Python\Python36-32>

If someone could help me understand what I am doing wrong that would be awesome. And please be very clear in your descriptions, I'm not well versed. (Yet I hope)

Upvotes: 0

Views: 11831

Answers (2)

Ana Todor
Ana Todor

Reputation: 801

You could also try this:

  1. Find a .py file (any, even a blank).
  2. Right click on it and choose: "Open with>" and then select "Choose program...".
  3. This pops up a list of all programs - select python, and check the box "Always use the selected program to open this kind of file" and then click OK.

Checking this box resets file associations and fixes this problem for the command line.

The problem can arise again if you tell Windows to open up .py files in a text editor as default.

Upvotes: 1

bennerv
bennerv

Reputation: 86

You have to run the python command in the directory that contains the file, or you must give the full path of the file.

If you wanted to run it as it was you would do:

py C:\Users\Davidjb7\AppData\Local\Programs\Python\Python36-32\hello.py

If you move the file into your current working directory when programming, you should just be able to run py hello.py.

Upvotes: 2

Related Questions