Douglas Su Douglas Su - 1 year ago 444
Python Question

how to set different PYTHONPATH variables for python3 and python2 respectively

I want to add a specific library path only to python2. After adding

export PYTHONPATH="/path/to/lib/"
to my
, however, executing python3 gets the error: Your PYTHONPATH points to a site-packages dir for Python 2.x but you are running Python 3.x!

I think it is due to that python2 and python3 share the common

So, can I set different
variables respectively for python2 and python3. If not, how can I add a library path exclusively to a particular version of python?

Answer Source

Create file mymodule.pth in python2 dist-packages path, (/usr/lib/python2.7/dist-packages) and add one line containing the directory to add to python path.
Do the same thing with python3.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download