How to import NumPy in the Python shell


I have tried importing NumPy in Python, but it did not succeed:

>>> import numpy as np

   Traceback (most recent call last):
   File "<pyshell#3>", line 1, in <module>
   import numpy as np
   File "C:\Python27\lib\numpy\", line 127, in <module>
   raise ImportError(msg)
   ImportError: Error importing numpy: you should not try to import numpy from
   its source directory; please exit the numpy source tree, and relaunch
   your Python interpreter from there.

How can I fix this?

6/26/2018 10:43:32 PM

Accepted Answer

The message is fairly self-explanatory; your working directory should not be the NumPy source directory when you invoke Python; NumPy should be installed and your working directory should be anything but the directory where it lives.

6/26/2018 9:15:29 PM

On Debian/Ubuntu:

aptitude install python-numpy

On Windows, download the installer:

On other systems, download the tar.gz and run the following:

$ tar xfz numpy-n.m.tar.gz
$ cd numpy-n.m
$ python install

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow