1

I have somehow a mess with my python versions and or pip version. As a consequence I have trouble to install numpy. I use the following default python version

>>> print(sys.version)
3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118]
>>> 

I have several python / pip version installed:

ola@think:~$ /usr/bin/python
python             python2.6          python2.7-config   python3            python3.5-config   python3.5m-config  python3m           python-config      pythontex3         
python2            python2.7          python2-config     python3.5          python3.5m         python3-config     python3m-config    pythontex          
ola@station:~$ 

If I want to import numpy I get the following:

>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'numpy'

However, running a pip3.5 install shows:

ola@station:~$ sudo pip3.5 install numpy
Requirement already satisfied: numpy in /usr/local/lib/python2.7/dist-packages
ola@station:~$ 

Something seems fishy, but I don't know what and how to resolve it. Help would be appreciated

Guillaume Jacquenot
  • 11,217
  • 6
  • 43
  • 49
math
  • 1,868
  • 4
  • 26
  • 60

2 Answers2

5

If you are not sure which pip program is associated with your multiple python version, I would recommend you to call pip from your desired python version. The following command calls pip module from your targeted python program.

python -m pip install numpy

With absolute paths, it gives

/usr/bin/python2.7 -m pip install numpy
/usr/bin/python3 -m pip install numpy
Guillaume Jacquenot
  • 11,217
  • 6
  • 43
  • 49
  • What would the command be (with absolute path) if multiple python3 versions have been installed via homebrew? I only have a /usr/bin/python3 folder and no /usr/bin/python3.8 folder. – Landon May 17 '22 at 13:25
  • I have a python3.8 located at /usr/local/lib/python3.8 but when I run *sudo /usr/local/lib/python3.8 -m pip install numpy* I get this error: *sudo: /usr/local/lib/python3.8: command not found*. – Landon May 17 '22 at 13:30
1

You don't just have multiple versions of pip installed, you have multiple versions of Python itself.

It looks like numpy is installed in your python 2.7 packages but not in your python 3.5 packages.

If you want to use numpy with python 2.7 then when you run the script you need to tell it to use python 2.7. See this answer.

Alternatively if you want to use numpy with python 3.5 then you need to install it in the correct location.

As a suggestion: Unless you need different versions of python installed for some reason I would recomend starting afresh with anaconda which comes with many scientific packages baked in (including numpy).

Charmander35
  • 115
  • 1
  • 11
  • thanks for your answer. I'm a bit confused :) so pip and python version are not linked? How would I then install a numpy for python 3.5? – math Jun 23 '17 at 14:53
  • pip is a package management system. perhaps this might clarify: https://en.wikipedia.org/wiki/Pip_(package_manager) – Charmander35 Jun 23 '17 at 14:54
  • sure that I got, but if run pip3.5 install numpy why isn't it installing numpy for python 3.5? It says its already installed but it isnt. – math Jun 23 '17 at 14:57
  • pip3.5 refers to the version of the package manger not the version of python, they just happen to be the same number. – Charmander35 Jun 23 '17 at 14:58
  • This might help https://stackoverflow.com/questions/10919569/how-to-install-a-module-use-pip-for-specific-version-of – Charmander35 Jun 23 '17 at 14:58