Mailing List Archive

Help! $PYTHONPATH trouble
The variable $PYTHONPATH doesn't seem to have any effect on my system (RH
Linux 6.0, Python 1.5.1). Here's what I get after defining $PYTHONPATH:

$ PYTHONPATH="home/possum/test/kwp"
$ echo $PYTHONPATH
home/possum/test/kwp
$ python
Python 1.5.1 (#1, Mar 21 1999, 22:49:36) [.GCC egcs-2.91.66 19990314/Li
on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import sys
>>> sys.path
['', '/usr/lib/python1.5/', '/usr/lib/python1.5/test',
'/usr/lib/python1.5/plat-linux-i386', '/usr/lib/python1.5/lib-tk',
'/usr/lib/python1.5/lib-dynload', '/usr/lib/python1.5/site-packages']
>>>

Shouldn't sys.path contain the value "home/possum/test/kwp"?
Help! $PYTHONPATH trouble [ In reply to ]
First, you need to either export PYTHONPATH or use the assignment as a
prefix, thus (assuming bash):

$ PYTHONPATH="home/possum/test/kwp"
$ export PYTHONPATH
$ python
or
$ PYTHONPATH="home/possum/test/kwp" python

Second, shouldn't that path start with a "/"?

Erik Stewart <possum@n-space.org> wrote in message
news:37B33980.A5318181@n-space.org...
The variable $PYTHONPATH doesn't seem to have any effect on my system (RH
Linux 6.0, Python 1.5.1). Here's what I get after defining $PYTHONPATH:
Help! $PYTHONPATH trouble [ In reply to ]
Evan Simpson wrote:
>
> First, you need to either export PYTHONPATH or use the assignment as a
> prefix, thus (assuming bash):
>
> $ PYTHONPATH="home/possum/test/kwp"
> $ export PYTHONPATH
> $ python
> or
> $ PYTHONPATH="home/possum/test/kwp" python

Thanks! It works fine now! I knew I must be missing something simple,
but I couldn't figure out what.

>
> Second, shouldn't that path start with a "/"?

Oops :@


>
> Erik Stewart <possum@n-space.org> wrote in message
> news:37B33980.A5318181@n-space.org...
> The variable $PYTHONPATH doesn't seem to have any effect on my system (RH
> Linux 6.0, Python 1.5.1). Here's what I get after defining $PYTHONPATH:
Help! $PYTHONPATH trouble [ In reply to ]
Erik Stewart <possum@n-space.org> writes:
| The variable $PYTHONPATH doesn't seem to have any effect on my system (RH
| Linux 6.0, Python 1.5.1). Here's what I get after defining $PYTHONPATH:
|
| $ PYTHONPATH="home/possum/test/kwp"
| $ echo $PYTHONPATH
| home/possum/test/kwp
| $ python

You need to export the variable into the environment, or it's only a
shell variable that isn't inherited by python or other programs.

$ PYTHONPATH="home/possum/test/kwp"
> $ export PYTHONPATH
$ printenv PYTHONPATH
home/possum/test/kwp
$ python

Just to make it more confusing, if PYTHONPATH were already an environment
variable you wouldn't have had to export it, and there are several ways
to express that export, too: export NAME=val, NAME=val export NAME, etc.

Donn Cave, University Computing Services, University of Washington
donn@u.washington.edu
Help! $PYTHONPATH trouble [ In reply to ]
Erik Stewart writes:

> $ PYTHONPATH="home/possum/test/kwp"
> $ echo $PYTHONPATH
> home/possum/test/kwp
> $ python
> Python 1.5.1 (#1, Mar 21 1999, 22:49:36) [.GCC egcs-2.91.66 19990314/Li
> on linux-i386
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import sys
> >>> sys.path
> ['', '/usr/lib/python1.5/', '/usr/lib/python1.5/test',
> '/usr/lib/python1.5/plat-linux-i386', '/usr/lib/python1.5/lib-tk',
> '/usr/lib/python1.5/lib-dynload', '/usr/lib/python1.5/site-packages']

Try exporting the variable. The way you are setting it above, it becomes a
shell variable, not an environment variable - it's not inherited by
sub-processes. I think if you do

>>> import os
>>> printos.environ['PYTHONPATH']

you'll see that PYTHONPATH is in fact not in Python's environment.

Do "export PYTHONPATH" before starting Python and you'll get the
expected results. Unless of course you have some other completely
different problem ;-)