2

I am trying to run a python script from the windows command prompt, but I receive the following error message:

"python: can't open file 'pacman.py': [Errno 2] No such file or directory"

when I try the command:

c:\Program Files (x86)\Python27>python pacman.py

This particular python script file pacman.py is located in the following folder:

C:\Users\Chris\Dropbox\edX\CS188x\search

So I added this folder to PYTHONPATH and confirmed that is was there using the following code:

>>> import sys
>>> sys.path
['', 'C:\\Program Files (x86)\\Python27\\Lib\\idlelib', 'C:\\Users\\Chris\\Dropbox\\edX\\CS188x\\search', 'C:\\windows\\syste...

I also checked the permissions on this file:

>>> os.access("C:\Users\Chris\Dropbox\edX\CS188x\search\pacman.py",os.W_OK)
True
>>> os.access("C:\Users\Chris\Dropbox\edX\CS188x\search\pacman.py",os.R_OK)
True
>>> os.access("C:\Users\Chris\Dropbox\edX\CS188x\search\pacman.py",os.X_OK)
True

So I am really not sure why I can't run this file, even though its path has been added to PYTHONPATH. Any help would be greatly appreciated. Thank you.

Chris Ferone
  • 21
  • 1
  • 2

4 Answers4

2

PYTHONPATH is used by the python interpreter. It is not the same as Windows' PATH environment variable. You can't use it as a search path for passing files to the interpreter on the command line.

So, you need to specify a valid path to the file. Either by using he same command as you've been trying with the difference being your current directory is the same as the location of pacman.py, or by specifying the full path to the file.

marklap
  • 471
  • 4
  • 15
  • If I change the directory in command prompt to the location of the pacman.py file, I get a different error message that says that command prompt does not recognize the syntax "python pacman.py" (see my comment above). – Chris Ferone Oct 11 '12 at 00:07
  • 1
    Sounds like the python executable isn't in your PATH. Use the full path to your python.exe when in the pacman.py folder or the full path to pacman.py when in the python.exe folder. – marklap Oct 11 '12 at 00:28
1

did you try running the script from its directory?

i can only guess, but maybe its some issue with the file being located inside your dropbox folder...

Seismoid
  • 146
  • 7
0

python "C:\Users\Chris\Dropbox\edX\CS188x\search\pacman.py"

or

cd C:\Users\Chris\Dropbox\edX\CS188x\search\
"c:\prorgam files (x86)\python27\python" pacman.py
Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • Thanks for your response. If I change the directory, I get a different error message: "'python' is not recognized as an internal or external command, operable program or bath file." I can only run the python filename.py command when the directory is set to c:\prorgam files (x86)\python27 – Chris Ferone Oct 10 '12 at 23:57
  • fixed ... sorry ... `c:\Program Files (x86)\Python27` should be on your path – Joran Beasley Oct 11 '12 at 00:05
0

SOLVED! So the comments were right in that I had to change the directory to the location of the file, but what was missing was that I had to edit the system environment variable PATH to include the location of python.exe, which is my case was C:\program files (x86)\python27 but for most people is just C:\python27. Thanks everyone for all your help!

Chris Ferone
  • 21
  • 1
  • 2