Python/C and PYTHONPATH

Tero Pihlajakoski tepihlaj at NOpaju.SPAMoulu.fi
Mon Jan 5 11:17:52 EST 2004


Jeff Epler <jepler at unpythonic.net> wrote:
> You'd need to tell us how you're invoking Python.  When the Python

Take a look at:  
http://www.python.org/doc/current/ext/pure-embedding.html.  Basically,
it's about same (and I tested with it too, same results: failing)

> 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

If I run "python" as a shell (python <scriptname>), everything works ok.
Says path is ok: [ '', '<thelib>', ... ]. However, from C, something works
differently: PyRun_SimpleString("import sys\nprint sys.path"); Shows no ''
(the rest is ok). The question is: Why is there no '', and what is the
"official/safe" way to set it? Just insert it to the list? (Setting
"PYTHONPATH= " helps, but I'd like it to run "off the box")

Tero




More information about the Python-list mailing list