Can't see numpy etc after upgrading Python on Ubuntu

Chris Angelico rosuav at
Tue Dec 20 00:36:15 EST 2016

On Tue, Dec 20, 2016 at 4:08 PM,  <ozpeterballard at> wrote:
> I use Python on Ubuntu 12.04. Recently I upgraded Python from 2.7.3 to 2.7.12. I did the upgrade via the source, i.e. download (from ), tar, ./config, sudo make install.
> After the upgrade, python could no longer see the 3rd party modules I use (numpy, scipy, matplotlib, cython). I can point PYTHONPATH to the cython files, but I can't work out how to include numpy, scipy and matplotlib.
> It's no good asking Ubuntu to upgrade, because apt-get tells me that numpy, scipy and matplotlib are all up to date.
> So what do I do so I can see these packages again?

First off, you're running a still-in-support old version of Ubuntu, so
check whether you can upgrade Python using apt-get. Check not just the
version number, but any features you need. I don't know whether Ubuntu
do this, but Red Hat often backport bug fixes and security patches
onto older builds of Python; what you get is named according to the
oldest component in it, but might well have a number of newer

But once you decide to build Python from source, you have to choose
between overwriting your existing Python (probably in /usr/bin) or
creating a new one (in /usr/local/bin). By default, untarring,
configuring without args, building, and installing, will give you
something in /usr/local/bin - which most likely means you're leaving
behind all the Python modules installed with apt-get. You also won't
touch anything that uses libpython, or anything like that. This is the
safe option. So, how do you get numpy etc into your new Python? Most
likely, using pip. Try this:

sudo apt-get build-dep python-numpy
sudo python -m pip install numpy

That'll build numpy from source. (I may have the package name wrong;
that's what it's called on my Debian, but it might be different on
Ubuntu.) It'll take a while, so if you're on a system with a slow CPU
and/or not much memory, be patient. But that should get numpy going
for you.


More information about the Python-list mailing list