I am working with both python 2 and python 3 on a daily basis. Should I be adding paths to PYTHONPATH that are specific to a python version, like the following, which is specific to python 2?
/usr/local/lib/python2.7/dist-packages
If the answer is yes, then would python 3 know not to use these modules?
If the answer is no, then where should I add the above path if not to PYTHONPATH?
Python 3 will attempt to load modules from your PYTHONPATH and fail. A possible solution to this is the following.
Set your PYTHONPATH to
/usr/local/lib/%PYTHON%/dist-packages
and create a file sitecustomize.py in the directory returned by
python -c "import site ; print site.getsitepackages()"
with the following content:
import sys
from distutils.sysconfig import get_python_version
sys.path = [x.replace('%PYTHON%', 'python{}'.format(get_python_version()))
for x in sys.path]
This will replace the relevant part of the directory name with whatever python version is executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With