[Tutor] unable to run file though dir path included

Alan Gauld alan.gauld at btinternet.com
Wed Dec 7 00:37:54 CET 2011


On 06/12/11 18:57, surya k wrote:
> I have included the path directory of the file but still I couldn't run it!.
>

The question is whicvh file?

Instead of telling us what you did it woyuld be more useful to cut n 
paste the actual command used into the mail (including the prompt since 
it usually shows which directory you are in)

> 1. I created a .pth file and wrote all required path list's and saved in
> "site-packages" of python dir.
> ( python\Lib\Site-packages).

That only helps with imports.

> 2. I also included python path ( c:\python27\) in system path so as to
> run it using command prompt.

That will help Wiondows find python.exe but has no affect omn whether 
Windows can see foo.py

> Now when I use this command to run a file "foo.py" at command prompt (
> run>cmd )
>
> command: "python foo.py".. it isn't running.
>
> The following error is shown.
>
> " python: can't open file 'foo': [ Errno 2] no such file or directory".

Notice that the error says it is foo.py that it cannot find.
You need to provide the path to foo.py (or change into the directory 
where it lives)


> But the following command didn't give me an error in python shell
>
> " import foo"

Thats because import uses the PYTHONPATH and your .pth file
to find files.

Windows doesn't know about them.

Incidentally the easiest way to run foo.py in Windows is simply to 
double click it in Windows explorer... Although you may need to add a 
pause line (eg raw_input("Hit enter to quit") ) at the end to see the 
output.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list