Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't pip updating my numpy and scipy?

My problem is that pip won't update my Python Packages, even though there are no errors.

It is similar to this one, but I am still now sure what to do. Basically, ALL my packages for python appear to be ridiculously outdated, even after updating everything via pip. Here are the details:

  • I am using pip, version 1.5.6.
  • I am using Python, version 2.7.5
  • I am on a Mac OSX, verion 10.9.5.

Using that, I have:

  • My numpy version is 1.6.2.
  • My scipy version is 0.11.0.
  • My matplotlib version is 1.1.1.

Even after I try:

sudo pip uninstall numpy

Followed by:

sudo pip install numpy

They both complete successfully, but when I go into python and check the version of numpy, it is still the old one. (As are all the other packages).

Not sure what is going on here?... How can this be fixed? P.S. I am new to this, so I might need explicit instructions. Thanks. Also, if anyone wants, I can provide a screenshot of pip as it is installing numpy.

EDIT:

Commands I ran as per the comments:

$which -a pip
/usr/local/bin/pip
$ head -1 $(which pip)
#!/usr/bin/python
$ which -a python
/usr/bin/python
like image 524
Spacey Avatar asked Oct 15 '14 19:10

Spacey


People also ask

Can I install SciPy with pip?

Method 1: Using pip to install Scipy Package Step 1: Install the latest Python3 in MacOS. Step 2: Check if pip3 and python3 are correctly installed. Step 3: Upgrade your pip to avoid errors during installation. Step 4: Enter the following command to install Scipy using pip3.

Is SciPy compatible with NumPy?

SciPy attempts to be compatible with at least the 4 previous releases of NumPy. In particular, SciPy cannot rely on features of just the latest NumPy, but needs to be written using what is common in all of those 4 releases 2. The table shows the NumPy versions suitable for each major Python version.

What is the newest version of NumPy?

Sep 10, 2020 – NumPy 1.19. 2 is now available. This latest release in the 1.19 series fixes several bugs, prepares for the upcoming Cython 3.


1 Answers

In OS X 10.9, Apple's Python comes with a bunch of pre-installed extra packages, in a directory named /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python. Including numpy.

And the way they're installed (as if by using easy_install with an ancient pre-0.7 version of setuptools, but not into either of the normal easy_install destinations), pip doesn't know anything about them.

So, what happens is that sudo pip install numpy installs a separate copy of numpy into '/Library/Python/2.7/site-packages'—but in your sys.path, the Extras directory comes before the site-packages directory, so import numpy still finds Apple's copy. I'm not sure why that is, but it's probably not something you want to monkey with.


So, how do you fix this?

The two best solutions are:

  • Use virtualenv, and install your numpy and friends into a virtual environment, instead of system-wide. This has the downside that you have to learn how to use virtualenv—but that's definitely worth doing at some point, and if you have the time to learn it now, go for it.

  • Upgrade to Python 3.x, either from a python.org installer or via Homebrew. Python 3.4 or later comes with pip, and doesn't come with any pip-unfriendly pre-installed packages. And, unlike installing a separate 2.7, it doesn't interfere with Apple's Python at all; python3 and python, pip3 and pip, etc., will all be separate programs, and you don't have to learn anything about how PATH works or any of that. This has the downside that you have to learn Python 3.x, which has some major changes, so again, a bit of a learning curve, but again, definitely worth doing at some point.


Assuming neither of those is possible, I think the simplest option is to use easy_install instead of pip, for the packages you want to install newer versions of any of Apple's "extras". You can get a full list of those by looking at what's in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python. When you upgrade numpy, you probably also want to upgrade scipy and matplotlib; I think everything else there is unrelated. (You can of course upgrade PyObjC or dateutil or anything else you care about there, but you don't have to.)

This isn't an ideal solution; there are a lot of reasons easy_install is inferior to pip (e.g., not having an uninstaller, so you're going to have to remember where that /Library/blah/blah path is (or find it again by printout out sys.path from inside Python). I wouldn't normally suggest easy_install for anything except readline and pip itself (and then only with Apple's Python). But in this case, I think it's simpler than the other alternatives.

like image 65
abarnert Avatar answered Oct 14 '22 14:10

abarnert