How to Import Numpy in the Python Shell
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...
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?
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.
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 setup.py install