If you have several versions of an installed package, say, for example, SciPy:
>>> import scipy; print(scipy.__version__); print(scipy.__file__) 0.17.0 /usr/lib/python3/dist-packages/scipy/__init__.py
and I would like the user version (installed, for example, using pip install --user --upgrade scipy
) to be preferable, requires the usercustomize.py file in ~/.local/lib/python3.5/site-packages/
, for example this content:
import sys, os my_site = os.path.join( os.environ['HOME'], '.local/lib/python%d.%d/site-packages' % ( sys.version_info[0], sys.version_info[1])) for idx, pth in enumerate(sys.path): if pth.startswith('/usr'): sys.path.insert(idx, my_site) break else: raise ValueError("No path starting with /usr in sys.path")
(the for loop selection index ensures that packages installed in "development mode" take precedence), now we get our custom version of SciPy:
>>> import scipy; print(scipy.__version__); print(scipy.__file__) 0.18.1 /home/user/.local/lib/python3.5/site-packages/scipy/__init__.py
source share