[Tutor] How to execute given script from the command line by just
giving "python script.py" from different directories?
Tue, 25 Sep 2001 22:09:33 -0400
On Sun, Sep 23, 2001 at 05:12:27PM +0530, Ajaya Babu wrote:
| I am facing a small problem. I want to execute python script from any
| directory in C: dirve..., I am working on both Linux and Windows. to test
| this applications...
| In linux I want to execute the python script which present in the directory
| C:\python20\projects\VirtualHandset.. by just typing
This is a bit confusing because it is impossible to have a directory
called 'C:\python20\projects\VirtualHandset' in Linux.
| "python VirtualHandset.py" from the command line or from the process That I
| start from the C routine...,
You can only do this if the script is in the PATH, and then you
execute the script directly.
| I am able to execute this script by giving obsolute path..., but If I try
| from C:\python20 to execute this script it is giving python can not open
| this file. I set the python.pth file path as
| C:\python20\projects\VirtualHandset and also set the system environment
| variable ...,
That is only used for imports, not for executing a script. Python
simply tries to open the file given as an argument and execute it.
The .pth and PYTHONPATH stuff is used only for import statements.
| But it is telling still it can not open this file. Can any one suggest the
| way I can tell python interpretor that it should look the given directories
| for the script file ?
For Unix-type systems put the .py file in a directory in the PATH,
such as /usr/bin, /usr/local/bin or ~/bin. Also make sure the script
is executable and has the #! line at the beginning. You can then type
at the prompt and the shell will locate the script in the PATH and
execute it. If you name the file 'VirtualHandset' instead of
'VirtualHandset.py' then you can simply type
to run it. Any other modules must have the .py extension though.
It is much the same on Windows, excpet that there really aren't any
standard directories in the PATH that I am aware of.