Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't import numpy

Tags:

python

numpy

When I try to import numpy on Python, it says:

ImportError: No module named numpy

If I try to install numpy, it says it has already been installed. It seems like it's been installed, but in a wrong place? I don't know where it should be though.

Python version is 2.4.6, but if I try to install a newer version, like 2.7, it says it has already been installed.

like image 835
user3443649 Avatar asked May 26 '26 18:05

user3443649


1 Answers

You can ask Python if numpy is installed, by searching through sys.path:

>>> import os
>>> import sys
>>> for p in sys.path:
...  if os.path.exists(os.path.join(p, 'numpy')):
...   print p
...   break
... else:
...  print "Numpy not found"
/usr/lib/python2.7/dist-packages

In this case, I have numpy installed in /usr/lib/python2.7/dist-packages. "Numpy not found" will be printed if it's not installed.

If you're on Windows (sounds like maybe?) then you need to make sure that the path is set up correctly. It sounds like you may have more than one python installed, and numpy is being installed in one of them, but your default interpreter is the other one.

like image 178
Seth Avatar answered May 28 '26 08:05

Seth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!