Python/C and PYTHONPATH

Jeff Epler jepler at unpythonic.net
Mon Jan 5 08:47:54 EST 2004


You'd need to tell us how you're invoking Python.  When the Python
executable is invoked without arguments, the current directory is on the
sys.path:

$ python
Python 2.2.2 (#1, Feb 24 2003, 19:13:11) 
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path[0]
''

When you run a script, the directory of that script is in sys.path[0]:
$ echo "import sys; print sys.path[0]" > /tmp/script.py
$ python /tmp/script.py
/tmp

Some Python editors may put the directory where they reside on sys.path,
but not the current directory.  They might do other startup that is
different from normal.  The newest Python I have on this machine
is 2.3b1, and its idle puts these elements at the start of Pythonpath:

Python 2.3b1 (#16, May 19 2003, 10:22:28) 
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> import sys
>>> sys.path[:2]
['/home/jepler', '/usr/local/bin']

... so instead of "the current directory" ('' or '.'), sys.path[0]
is "the directory idle was invoked from", and that's followed by "the
directory where the idle script lives".

Jeff




More information about the Python-list mailing list