Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import NumPy in the Python shell

Tags:

python

numpy

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

>>> import numpy as np
    x=np.array([[7,8,5],[3,5,7]],np.int32)

   Traceback (most recent call last):
   File "<pyshell#3>", line 1, in <module>
   import numpy as np
   File "C:\Python27\lib\numpy\__init__.py", 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?

like image 747
hafizul asad Avatar asked Aug 10 '12 17:08

hafizul asad


People also ask

How do I know if NumPy is installed in Terminal?

Go to Python -> site-packages folder. There you should be able to find numpy and the numpy distribution info folder. If any of the above is true then you installed numpy successfully.

Which command is used to install NumPy package in Python?

In the terminal, use the pip command to install NumPy package. 3. Once the package is installed successfully, type python to get into the python prompt.


2 Answers

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.

like image 179
Wooble Avatar answered Sep 19 '22 06:09

Wooble


On Debian/Ubuntu:

aptitude install python-numpy

On Windows, download the installer:

http://sourceforge.net/projects/numpy/files/NumPy/

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

$ tar xfz numpy-n.m.tar.gz
$ cd numpy-n.m
$ python setup.py install
like image 40
shashank Avatar answered Sep 22 '22 06:09

shashank