1
votes

I have python2.7.8 on mac, things I did:

  • sudo easy_install pip - worked.

  • pip install numpy:

Requirement already satisfied (use --upgrade to upgrade): numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python

ddd

I also did "pip upgrade numpy" - no luck. What's wrong?

4

4 Answers

2
votes

Your problem is a conflict of different Python versions.

I would recommend installing Python and all the packages, such as numpy, scipy, matplotlib, pandas, etc via Brew

See this tutorial: https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Homebrew-and-Python.md

You can verify which Python you're running with which python or which python3 in Terminal.

This solution is more flexible and cleaner in my opinion than using Conda/Miniconda. However it is also a bit more lengthy to install, as you need to have Xcode, devtools installed to build everything

1
votes

Could it be that you have multiple versions of python installed? What happens if you run python using the full path like this:

$ /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2

instead of just python2?

1
votes

In my experience on Mac (and other OS too) it is best to go with Anaconda / Miniconda. This is especially true for packages like NumPy and others from scientific stack.

While Anaconda is a full-blown distribution with about 200 packages, Miniconda is just Python with a few basic libraries. The big advantage is that all packages install as binary. Further, it makes it very simple and stable to install multiple Python versions side by side. For example:

conda create -n py27 python=2.7  

creates a new environment with Python 2.7. Activate with:

source activate py27

Now:

conda install numpy 

installs NumPy cleanly.

You can do the same for Python 3.5 and switch between environments with source activate.

-1
votes

After jumping from one stackoverflow answer to another I found the solution!

my problems were: numpy at different location( actually at right, expected-to-be location). It was the IDLE that looks for its own default folder where python2.7 installed.

I checked that my numpy is working like this, run this script to check it is working:

import os
import sys
import pygame
sys.path.insert(0, '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python')
import numpy
pygame.init()
print "( using __version__): " + numpy.__version__
print numpy.version.version
user_paths = os.environ['PYTHONPATH']
print(user_paths)

sys.path insertion adds additional path to IDLE, so it knows where to look for numpy. Then I check if numpy truly imported - i just print its version. Right now it is 1.8.0rc.

I want to find a way to avoid using this syspath insertion all the time. So far so good - for now.