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

W W srilyk at gmail.com
Tue Sep 30 23:05:32 CEST 2008

On Tue, Sep 30, 2008 at 2: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

I'm not entirely sure about Windows, but my guess is that your problem is
that the pythonpath isn't what you need to set. I would venture to guess
that it's searching for test.py in your current path. If I'm correct in my
thinking, all it does when you set the python path is tells python to
execute in that directory, so if your script contains something like f =
open("myfile.txt", "w") it will put it in that directory.

You may want to try this:

The path is now managed by Windows 2000 / Windows XP and not the
autoexec.bat or autoexec.nt files. To change the system environment
variables, follow the below steps.

   1. From the desktop <http://www.computerhope.com/jargon/d/desktop.htm>,
   right-click My Computer and click properties.
   2. In the System Properties
   click on the Advanced tab <http://www.computerhope.com/jargon/t/tab.htm>.
   3. In the Advanced section, click the Environment Variables
   4. Finally, in the Environment Variables window, highlight the path
   variable in the Systems Variable section and click edit. Add or modify the
   path lines with the paths you wish the computer to access. Each different
   directory is separated with a semicolon as shown below.

   C:\Program Files;C:\Winnt;C:\Winnt\System32


Try adding the path to your code in that way, and see if it works. HTH,

To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080930/15082c86/attachment.htm>

More information about the Tutor mailing list