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

Timothy Grant timothy.grant at gmail.com
Wed Oct 1 07:54:25 CEST 2008

On Tue, Sep 30, 2008 at 9:01 PM, Pierre Dagenais <pierre.dagenais at ncf.ca> wrote:
> Timothy Grant wrote:
>> On Tue, Sep 30, 2008 at 12:58 PM, Pierre Dagenais
>> <pierre.dagenais at ncf.ca> wrote:
>>> The file test.py is in I:\Python25\MyCode,
>>> if I enter:
>>>  C:\>Python25\MyCode\python25 test.py at the DOS prompt, everything works
>>> as
>>> I would expect.
>>> However when I enter the same command from any other directory I get this
>>> error:
>>>  C:\>python test.py
>>>  python: can't open file 'test.py' : [Errno 2] No such file or directory
>>> I've set the environment variable pythonpath as
>>>  C:\>set pythonpath = C:\\Python25\\MyCode
>>> what am I doing wrong,
>>> Thank u for your help,
>>> _______________________________________________
>>> Tutor maillist  -  Tutor at python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>> You need to give the full path to your test.py file.
>> PYTHONPATH sets the python library search path.
>>  Thank you Tim,
>> Definitively C:\python \python25\mycode\test.py does work. If you're right
>> about having to give the full path, and I suspect you are, Then this means
>> that python knows to search the currennt working directory for  the file to
>> execute, but nowhere else. It seems a strange behavior. Maybe this is on Mr.
>> Guido van Rossum todo list.

Why is that strange? Would you expect any other program not on the
path to execute without a fully qualified path? Make your python code
executable, and put it somewhere on the path and I'm quite sure it
would run as expected (though it has been over 10 years since I last
had to work on a Windows box so I'm not quite sure how to do that).

Stand Fast,
tjg.  [Timothy Grant]

More information about the Tutor mailing list