[Tutor] Idle - ImportError: No module named numpy

Oscar Benjamin oscar.j.benjamin at gmail.com
Tue Mar 10 01:25:51 CET 2015


On 9 March 2015 at 18:09, Markos <markos at c2o.pro.br> wrote:
> I installed numpy in Debian (6.0) with the command:
> apt-get install python-numpy
>
> I just find that this package is exclusively for python 2.5 and 2.6
>
> The idle3 use Python 3.1.3.
>
> How to install numpy for Python 3 in order to use it with the idle?
>
> Is there any simple way?

Hi Markos,

I'm not sure about Squeeze but on this Ubuntu 14.04 system you can
install numpy for Python 3 by typing:

    $ sudo apt-get install python3-numpy

The Python 3 version of the package is a relatively new addition to
the repositories though so it may not be available in Squeeze.

If there is no package then you can build numpy yourself. It's not too
hard to do. First make sure that you have pip installed for python3.
You can check if it's installed by typing:

    $ python3 -m pip

If it says

    /usr/bin/python3: No module named pip

then you don't have pip. You may be able to install pip with

    $ sudo apt-get install python3-pip

If not then you can install it by downloading the get-pip.py script from here:

    https://pip.pypa.io/en/latest/installing.html

Once you have that you can run it as

    $ sudo python3 get-pip.py

Once pip is installed you can use it to install lots of things
including numpy. For numpy in particular though you'll need to first
install the compilers and Python 3 header files:

    $ sudo apt-get install build-essential python3-dev

Now you can use pip to install numpy for python3:

    $ sudo python3 -m pip install numpy

This will download numpy from PyPI and then try to compile and install
it. Compiling numpy takes a while and you will see a lot of strange
compiler messages. If it fails then just post the very last part of
the output here. It will probably mean that you need to install more
compilers or something.

If it succeeds then you should be able to import numpy e.g.:

    $ python3
    Python 3.4.0 (default, Apr 11 2014, 13:05:11)
    [GCC 4.8.2] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import numpy
    >>> numpy.cos(1)
    0.54030230586813977


Oscar


More information about the Tutor mailing list