lars
lars

Reputation: 1986

Python numpy update from 1.6 to 1.8

I have installed numpy 1.8. But when I do print numpy.__version__ it says 1.6.

What do I have to change to get python to realize where numpy is? Working on a Mac (10.9). I'm using python 2.7.6.

Edit:

I've tried to delete all my versions of numpy. I did pip uninstall numpy. And then I typed:

python import numpy print numpy.version

and it printed out 1.6.2

I can't delete numpy apparently.

Upvotes: 4

Views: 7434

Answers (3)

ycw9921133
ycw9921133

Reputation: 21

I assume you have inconsistent version of numpy in two paths

/Library/Python/2.7/site-packages

and

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python

My solution is rename (or delete) the one you don't like (possibly the older version) and symlink the other (the newer version) back to the directory which you deleted numpy folder from.

Upvotes: 2

stachyra
stachyra

Reputation: 4593

I am running Python 2.7.5 on Mac OS X 10.9.4, and this appears to be some kind of weird bug in how the Macintosh factory-installed version of Python is handling upgraded package installations.

In my case, when I do:

sudo pip uninstall numpy

it removes the version of numpy installed under

/Library/Python/2.7/site-packages

However, this does not mean that numpy is fully removed from the system! There are a second set of "backup" versions of several Python packages installed also at:

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python

When I install numpy using the /usr/bin/easy_install utility that Apple shipped with the OS X system, the latest version (currently at 1.9.0, as of this posting) of numpy is loaded into Library/Python/2.7/site-packages, just as one would expect, and it correctly precedes the "OS X system default" version of numpy in the module load path so that the latest version of numpy is loaded when I do import numpy in Python. However--and this is the really weird, apparently buggy behavior!--when I uninstall numpy, and instead reinstall using either pip, or by doing:

sudo python setup.py install

on a .tar.gz distribution downloaded directly from sourceforge, the upgraded installation does not appear to take precedence in the Python module load path, even though it is also installed under /Library/Python/2.7/site-packages!

Anyway, to fix the problem (or rather, I should probably say, to work around the bug, at least on Max OS X), follow this procedure:

  1. Uninstall the numpy package from /Library/Python/2.7/site-packages using the method of your choice (pip uninstall numpy appeared to work for me)
  2. Verify that there is indeed no longer any numpy package still remaining under /Library/Python/2.7/site-packages
  3. Reinstall numpy using the factory-included /usr/bin/easy_install. Do not use any other alternative method, at least not if you want to use numpy with the Apple factory-installed version of Python 2.7

Alternatively, using a completely different distribution of Python (e.g., Canopy or Anaconda), as one of the other commenters already mentioned, should also work as well.

Upvotes: 8

wim
wim

Reputation: 362746

You mentioned in the comments that removing with pip and OS package manager didn't work for you. If you may have used easy_install in the first place, also try easy_install -m for removal. If all else fails, you can clobber the files manually (the imports are taken from sys.path so the first version found in that list is where the import will come from).

Load up interactive python interpreter and check the physical location of the files:

>>> import numpy
>>> numpy.__file__
'/home/wim/.virtualenvs/xyz/local/lib/python2.7/site-packages/numpy/__init__.pyc'

This will tell you which directory you need to delete in order to prevent the unwanted version from being imported.

This is a somewhat impolite way to "uninstall" numpy, so use as a last resort.

Upvotes: 2

Related Questions