Search path for python script

G

grt

I'm new to python, running it under cygwin. This must be easy but I
haven't figured it out. I'm trying to run a script by typing:

python test.py

where test.py is in a directory I've added to PYTHONPATH, but test.py
is not found. Perhaps PYTHONPATH only applies to modules imported
within a script. I didn't notice an option to python to search the
standard path, like Perl -S.

How is this done?
 
S

Steve Holden

grt said:
I'm new to python, running it under cygwin. This must be easy but I
haven't figured it out. I'm trying to run a script by typing:

python test.py

where test.py is in a directory I've added to PYTHONPATH, but test.py
is not found. Perhaps PYTHONPATH only applies to modules imported
within a script. I didn't notice an option to python to search the
standard path, like Perl -S.

How is this done?
The PYTHONPATH is only used to augment sys.path, which in turn is only
used for locating modules to import.

If you want to locate scripts then just put them on your PATH, and make
sure they are +x with a shebang line (#!/usr/bin/env python is the
commonest) at the head.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
 
P

Peter Otten

Am Wed, 12 Sep 2007 14:40:30 -0700 schrieb grt:
I'm new to python, running it under cygwin. This must be easy but I
haven't figured it out. I'm trying to run a script by typing:

python test.py

where test.py is in a directory I've added to PYTHONPATH, but test.py
is not found. Perhaps PYTHONPATH only applies to modules imported
within a script. I didn't notice an option to python to search the
standard path, like Perl -S.

How is this done?

python -m test

Peter
 
W

WGWhalley

This works for me under cygwin.

Start the script with the line
#! /usr/bin/python

Place the script in a directory shown by the command
echo $PATH

Invoke the script using its name, i.e.

test.py
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top