Peter Schumacher
Peter Schumacher

Reputation: 441

Environment Variables not in Python interpreter

HI i just run over a curious thing.

In my .bashrc looks like this:

PYTHONPATH=$PYTHONPATH:/home/pschu/ParaView-3.14.1-Build/Utilities/VTKPythonWrapping/site-packages:home/pschu/ParaView-3.14.1-Build/bin

ParaView_DIR=/home/pschu/ParaView-3.14.1-Build

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/pschu/ParaView-3.14.1-Builds/bin

So now when i start the python interpreter and type following:

>>>os.environ['PYTHONPATH']
 Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/usr/lib64/python2.7/UserDict.py", line 23, in __getitem__
 raise KeyError(key)
KeyError: 'PYTHONPATH'

same error with ParaView_DIR, but LD_LIBRARY_PATH has the additional Path.

in the shell they exist.

echo $PYTHONPATH
:/home/pschu/ParaView-3.14.1-Build/Utilities/VTKPythonWrapping/site-packages:home/pschu/ParaView-3.14.1-Build/bin

now when i do

export PYTHONPATH=$PYTHONPATH

before I run the python interpreter it works.

What's happening?

Upvotes: 2

Views: 2939

Answers (2)

cdarke
cdarke

Reputation: 44424

Did you export the variables?

export PYTHONPATH ParaView_DIR

LD_LIBRARY_PATH was probably already exported in one of your other startup files. Once a variable is exported it stays that way.

Exporting a variable makes it an environment variable, if you don't export then it is just local to the shell and a child process does not get a copy.

If you are using the C-shell (often indicated by the % prompt) then the syntax is different:

setenv PYTHONPATH $PYTHONPATH

Upvotes: 1

user647772
user647772

Reputation:

This works:

% PYTHONPATH=$PYTHONPATH:/tmp python

In Python:

>>> import os
>>> os.environ["PYTHONPATH"]
':/tmp'

Upvotes: 2

Related Questions