简体   繁体   中英

Can't import 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM