Not finding user-installed module despite PYTHONPATH!

Albert Hofkamp hat at se-46.wpa.wtb.tue.nl
Thu Nov 28 09:51:09 EST 2002


Hello all,

I want to run an interactive Python module through ssh. The basic solution is
something like

ssh -x remote_machine 'python -c "import mymodule ; mymodule.run()"'

I start this command through the popen2 module so I can communicate with
the module in another Python script.

Obviously, 'import' looks for mymodule in the python module searchpaths.
Since mymodule is not (yet :-) ) part of the python standard distribution,
I did a user-install (the home scheme of distutils) of the module at
$HOME/python.
I added the searchpath to the module into PYTHONPATH in my shell rc file
(export PYTHONPATH=$HOME/python/lib/python:.).
(both .bashrc and .zshrc (as well as the login scripts (.bash_profile,
.zlogin) to be on the safe side))

At my Linux (RH7.2) system, this approach works with bash.
It does _NOT_ work with zsh.

Note that interactively starting python and loading the mymodule works in
both shells (i.e. at that point in time, PYTHONPATH is correct).

Apparently, different shells perform different actions during startup, and
there is no guarantee that PYTHONPATH is set before the ssh command is run.

My question(s) is(are)
a) Did I miss something (in particular, w.r.t. ssh, the login process, or
   the shells)?

If not, the conclusion seems to be that environment variables cannot be relied
upon.

b) In that case, can I convince Python in another way to include a path in
   the module search without rebuilding Python itself?
c) If not, should Python not have another standard way for configuring?
   (The immediate thing that comes to mind is to have a .pythonrc file
   containing a Python script that is run upon startup of Python.)

Albert
-- 
Unlike popular belief, the .doc format is not an open publically available format.



More information about the Python-list mailing list