Proper way to set PYTHONPATH (including precedence)

Posted by Wells on Stack Overflow See other posts from Stack Overflow or by Wells
Published on 2010-04-22T22:32:38Z Indexed on 2010/04/22 22:33 UTC
Read the original article Hit count: 458

Filed under:
|

In .bashrc I have:

export PYTHONPATH=/home/wells/py-mlb

I've verified this is actually being set. so, in this directory is another directory called 'py_mlb'- the actual module.

So I go python -v and then import py_mlb but it does:

>>> import py_mlb
import py_mlb # directory /usr/local/lib/python2.6/dist-packages/py_mlb

Then I do import sys and print sys.path and I see:

>>> print sys.path
['', '/usr/local/lib/python2.6/dist-packages/python_memcached-1.44-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/pymc-2.1alpha-py2.6-linux-i686.egg', '/usr/local/lib/python2.6/dist-packages/nose-0.11.1-py2.6.egg', '/home/wells/py-mlb', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/local/lib/python2.6/dev-packages', '/usr/lib/pymodules/python2.6', '/usr/lib/pymodules/python2.6/gtk-2.0', '/usr/local/lib/python2.6/dist-packages']

So my path from .bashrc IS in there, and from the look of it it's even before dist-packages but it's importing the module from dist-packages.

How can I finagle this so the PYTHONPATH as defined by .bashrc takes precedence? Thanks!

© Stack Overflow or respective owner

Related posts about python

Related posts about bash