18

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 2

19

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.

Sign up to request clarification or add additional context in comments.

4 Comments

how to change my working directory. I know how to do it in matlab, but i am a new user of python and dont know how to do it.
In your terminal, make sure you're in some other directory before you launch python. As long as the numpy folder is living somewhere that is part of your system's PYTHONPATH variable, you can import numpy in python from anywhere on your system. If you're not sure what all of that means, google PYTHONPATH and importing in python.
i tried this but didnt work; ,>>> os.getcwd() 'C:\\Python27' >>> os.chdir('C:\working directory') >>> import numpy
cd ../.. and then open the python shell. It's saying you can't import numpy from inside of `C:\Python27\lib\numpy`
1

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 

1 Comment

He does not need NumPy installed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.