I want to add a specific library path only to python2. After adding export PYTHONPATH=\"/path/to/lib/\"
to my .bashrc
, however, executing python3 gets
I found that there is no way to modify PYTHONPATH
that is only for python2
or only for python3
. I had to use a .pth file.
What I had to do was:
$HOME/.local/lib/python${MAJOR_VERSION}.${MINOR_VERSION}/site-packages
.pth
file in that directory .pth
file is workFor more info on `.pth. file syntax and how they work please see: python2 docs and python3 docs.
(.pth
files in a nutshell: when your python interpreter starts it will look in certain directories and see the .pth
file, open those files, parse the files, and add those directories to your sys.path
(i.e. the same behavior as PYTHONPATH
) and make any python modules located on those directories available for normal importing.)