38

For python 3.2 I used sudo apt-get install python3.2-numpy.It worked. What to do for python3.3? Nothing I could think of works. Same goes for scipy, etc. Thanks.

Edit: this is how it looks like

radu@sunlit-inspired:~$ python3
Python 3.3.2 (default, Jul  3 2013, 10:17:40) 
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'numpy'
Loïc
  • 11,804
  • 1
  • 31
  • 49
Radu
  • 713
  • 1
  • 10
  • 13

6 Answers6

43

In the solution below I used python3.4 as binary, but it's safe to use with any version or binary of python. it works fine on windows too (except the downloading "get-pip.py" with wget obviously but just save the file locally and run it with python, see below).

This is great if you have multiple versions of python installed, so you can manage external libraries per python version.

So first, I'd recommend get-pip.py, it's great to install pip:

wget https://bootstrap.pypa.io/get-pip.py

Then you need to install pip for your version of python, I have python3.4 so for me this is the command:

python3.4 get-pip.py

Now pip is installed for this version and I'll use pip "contextualized" to that version this way:

python3.4 -m pip

So to install numpy for python3.4 I'll use :

python3.4 -m pip install numpy

Note that numpy is quite the heavy library. I thought my system was hanging and failing. But using the verbose option, you can see that the system is fine :

python3.4 -m pip install numpy -v

This may tell you that you lack python.h but you can easily get python headers:

Of course you want to keep using your python version in those commands

On Debian-like (Debian, Ubuntu, Kali, ...) :

apt-get install python34-dev

On RHEL (Red hat, CentOS, Fedora) it would be something like this:

yum install python34-devel

or more recently

dnf install python34-devel

If that doesn't work for you, there's a great topic with more coverage: fatal error: Python.h: No such file or directory

Finally, once you've got python header files you can just rerun the pip install command:

python3.4 -m pip install numpy -v
Loïc
  • 11,804
  • 1
  • 31
  • 49
14

From the terminal run:

  sudo apt-get install python3-numpy

This package contains Numpy for Python 3.

For scipy:

 sudo apt-get install python3-scipy

For for plotting graphs use pylab:

 sudo apt-get install python3-matplotlib
Nikhil
  • 290
  • 5
  • 12
11

The normal way to install Python libraries is with pip. Your way of installing it for Python 3.2 works because it's the system Python, and that's the way to install things for system-provided Pythons on Debian-based systems.

If your Python 3.3 is system-provided, you should probably use a similar command. Otherwise you should probably use pip.

I took my Python 3.3 installation, created a virtualenv and run pip install in it, and that seems to have worked as expected:

$ virtualenv-3.3 testenv
$ cd testenv
$ bin/pip install numpy
blablabl

$ bin/python3
Python 3.3.2 (default, Jun 17 2013, 17:49:21) 
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> 
Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
  • 3
    unfortunately my system Python is 2.7.3 so pip installs there. there is a pip-3.2 but no pip-3.3. – Radu Jul 03 '13 at 09:06
  • 1
    @Radu: Just like numpy needs to be installed specifically for Python 3.3, pip needs to be installed for Python 3.3. http://regebro.wordpress.com/2011/02/02/newbie-hint-on-installing-python-and-its-modules-and-packages/ – Lennart Regebro Jul 03 '13 at 09:13
  • i ran `python3 distribute_setup.py` and it tells me `Installing easy_install-3.2 script to /usr/local/bin` ! i can confirm that python3 is python3.3 not python3.2. – Radu Jul 03 '13 at 09:40
  • @Radu: I find it somewhat hard to believe that distribute_setup.py would create an easy_install-3.2 if executed with Python 3.3. If it really does, your installs are seriously messed up. – Lennart Regebro Jul 03 '13 at 12:17
  • I believe you. Yet this is what happens. Could you be so kind and tell me what would you do if you had this situation on your machine and you needed python3.3? Thank you. – Radu Jul 03 '13 at 13:42
  • @Radu: Uninstall all versions of Python 3 and reinstall them correctly. Read http://regebro.wordpress.com/2011/02/02/newbie-hint-on-installing-python-and-its-modules-and-packages/ first. Perhaps Zhenyas link to the deadnakes distro is an option as well. – Lennart Regebro Jul 03 '13 at 13:44
  • You have to activate the virtualenv before using pip and python: `source testenv/bin/activate` – Marco Sulla Feb 25 '16 at 22:46
  • pip works properly within a 32-bit Python installation (V 3.6.1) on a Windows 7 (64 bit) – MichaelHuelsen Jul 21 '17 at 06:46
5

I'm on Ubuntu 15.04. This seemed to work:

$ sudo pip3 install numpy

On RHEL this worked:

$ sudo python3 -m pip install numpy
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
AAAfarmclub
  • 2,202
  • 1
  • 19
  • 13
4

My issue was the failure to import numpy into my python files. I was receiving the "ModuleNotFoundError: No module named 'numpy'". I ran into the same issue and I was not referencing python3 on the installation of numpy. I inputted the following into my terminal for OSX and my problems were solved:

python3 -m pip install numpy
airvine
  • 631
  • 8
  • 23
1

On fedora/rhel/centos you need to

sudo yum install -y python3-devel

before

mkvirtualenv -p /usr/bin/python3.3 test-3.3
pip install numpy

otherwise you'll get

SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.
hobs
  • 18,473
  • 10
  • 83
  • 106