2

I'm trying to install numpy, matplotlib, and scipy in the right python version.

Initially I was testing with different python versions (3.2, 2.7, 2.6).

I removed all these versions using: How to uninstall Python 2.7 on a Mac OS X 10.6.4?

Afterwards, I reinstalled Python 2.7.11. when I try to install numpy, matplotlib and scipy, using pip, I get the following message: Requirement already satisfied (use --upgrade to upgrade) ...

In my terminal, I tried the following:

$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python

$ python
Python 2.7.11 (v2.7.11:.....)
.....
>>> import numpy
ImportError: No module named numpy

$ /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python
Python 2.7.10 (default, ......
.....
>>> import numpy
>>> numpy.__version__
'1.8.0rc1'

for some reason these packages got installed in 2.7.10 and not 2.7.11, which is the version I downloaded from python.org. Also, I don't even know how I got the 2.7.10 version.

How can I fix this issue?

Community
  • 1
  • 1
  • You should also add the exact statements you used to install numpy, and also check the path of the tool you used to install (e.g pip or setuptools) with `which -a ` – cel Mar 03 '16 at 07:47
  • `$ which -a pip` `/usr/local/bin/pip` The installation commands: `ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"` `export PATH=/usr/local/bin:/usr/local/share/python:$PATH` `$ easy_install pip` `pip install numpy` `pip install gcc` `pip install scipy` `brew install pkg-config` `pip install matplotlib` I just solved the issue by doing the following: I open my 2.7.11 python >>> import sys >>> sys.path.insert(0, '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python') and that fixed it! Thanks a lot for your help! – Khalid Almuteri Mar 03 '16 at 08:25

4 Answers4

4

You can also use macports (https://www.macports.org/) to install different versions of python, numpy, and matplotlib. It's really quite simple.

Alternatively, you can perhaps use anaconda (https://www.continuum.io/downloads), which uses conda, to achieve your goal.

bvilhjal
  • 136
  • 4
  • I recommend Anaconda as it installs all the related packages such as numpy, pandas etc together and the compatible ones. – Saket Mar 03 '16 at 08:23
  • 1
    I'd second the recommendation for going the Anaconda route. Particularly if you're using Numpy or anything that depends on Numpy (Pandas, Scipy, Sci-kit Learn). Continuum has access to the Intel MKL which gives you significant optimizations and pre-compiled C code specific to your operating system. https://docs.continuum.io/mkl-optimizations/ – rwhitt2049 Jun 12 '17 at 20:02
4

I recommend using virtualenv (with virtualenvwrapper: https://virtualenvwrapper.readthedocs.org). It is very easy to setup and you'll have absolutely no problems in future when you deal with multiple Python installations.

I work with virtualenv for years now and create for each project a separate virtual environment, which is always clean and I never have to deal with PATH, PYTHONPATH or whatever.

If you followed the virtualenvwrapper installation guide, you can simply create for example one virtualenv for everyday work via:

mkvirtualenv common -p /Library/Frameworks/Python.framework/Versions/2.7/bin/python

this will create the virtualenv and automatically activate it, so you can instantly install the packages you want:

pip install matplotlib numpy scipy

and every time you want to use it you type:

workon common

As you see above, you can specify the python executable via the -p flag. Each virtualenv will be a completely fresh and independent Python installation where you can use pip to install whatever you want (without root access of course).

tamasgal
  • 24,826
  • 18
  • 96
  • 135
3

It is likely to mean that you used pip or easy_install from another python version.

When you install your modules, make sure to use the correct pip version.

It might be /usr/local/bin/pip2.7 for example.

DevShark
  • 8,558
  • 9
  • 32
  • 56
0

If you install Anaconda from continuum.io, you'll get access to versions of many packages that have been tested to work with the version of Python that you are interested in working with. Here's the list that come with the current version of their distribution.

You also get access to conda, which is a package and environment manager. Think pip + virtualenv.

Once you have that, you can do

conda create -n my_env python=3.6 numpy pandas

This will install Python 3.6 and all of the dependencies for numpy and pandas into a virtual environment called my_env. Conda will make sure that you have the most up to date packages that work together.

To access your environment, you can do:

activate my_env

Now you're running Python in that environment with those installed packages. If you need more packages, you can either do conda install package_name. If conda can't find the package, you can still do pip install package_name.

Note that as an added bonus, you get an optimized and pre-compiled version of Numpy by way of the Intel MKL.

(From my comment on a previous answer)

I'd second the recommendation for going the Anaconda route. Particularly if you're using Numpy or anything that depends on Numpy (Pandas, Scipy, Sci-kit Learn). Continuum has access to the Intel MKL which gives you significant optimizations and pre-compiled C code specific to your operating system. docs.continuum.io/mkl-optimizations

rwhitt2049
  • 380
  • 4
  • 8