Using pip3-installed python 3 packages when apt-installed packages exist too?
I have numpy 1.8.2 installed in /usr/lib/python3/dist-packages (via apt), and the newest version (1.9.2) installed in /usr/local/lib/python3.4/dist-packages (via pip). Both paths are in sys.path (in that order), but only the older apt version is getting imported in python3.
➜ ~ sudo pip3 install --upgrade numpy
[sudo] password for naught101:
Real name of requirement numpy is numpy
Requirement already up-to-date: numpy in /usr/local/lib/python3.4/dist-packages
Cleaning up...
➜ ~ ipython3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
Type "copyright", "credits" or "license" for more information.
IPython 1.2.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import numpy
In [2]: numpy.version
Out[2]: <module 'numpy.version' from '/usr/lib/python3/dist-packages/numpy/version.py'>
In [3]:
KeyboardInterrupt
In [3]: numpy.version.version
Out[3]: '1.8.2'
In [5]: import sys
In [6]: sys.path
Out[6]:
['',
'/usr/local/bin',
'/usr/lib/python3/dist-packages',
'/usr/lib/python3.4',
'/usr/lib/python3.4/plat-x86_64-linux-gnu',
'/usr/lib/python3.4/lib-dynload',
'/usr/local/lib/python3.4/dist-packages',
'/usr/lib/python3.4/dist-packages',
'/usr/lib/python3/dist-packages/IPython/extensions']
(python3 does the same thing as ipython3 here)
How can I get python3 to use the newer version?
I can't just uninstall the apt version, because other packages depend on it.
This blog post explain the code logic behind this very well: How does python find packages?
Quoting it:
As the docs explain, sys.path is populated using the current working directory, followed by directories listed in your PYTHONPATH environment variable, followed by installation-dependent default paths, which are controlled by the site module.