How to tell a Python program where a shared library is?

Donn Cave donn at u.washington.edu
Thu May 3 13:42:38 EDT 2001


Quoth "Edward C. Jones" <edcjones at erols.com>:
| Suppose I have a shared library, say "mymodule.so". How do I tell a Python
| program where "mymodule.so" is? If necessary I can change the PATH environment
| variable. How is this done?

If python is going to import mymodule directly ("import my"), then
you can give python the location (just the directory, not the file
name) via PYTHONPATH

   $ PYTHONPATH=$mypath python
or
   $ PYTHONPATH=$mypath export PYTHONPATH     (innumerable variations)
   $ python

or push it into sys.path from the program itself -

   import sys
   sys.path.insert(0, mypath)

Try this to see both sides at work:

   PYTHONPATH=$mypath python -c 'import sys; print sys.path'

Now, don't do this on an NFS mounted filesystem.  You'll see that
this includes the current working directory.  If you let python
load a .so over NFS, it will be hard to reliably update that module.
You can change the file, python will still see the old one.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list