简体   繁体   中英

Python: modul not found after Anaconda installation

I've successfully installed Python 2.7 and Anaconda but when i try to import a library i get always this error:

>>> import scipy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named scipy

I've set up the PYTHONHOME to C:\\Python27 and PYTHONPATH to C:\\Python27\\Lib .

EDIT : content of PATH

In my $PATH variable i have C:\\Users\\Mattia\\Anaconda2 , C:\\Users\\Mattia\\Anaconda2\\Scripts and C:\\Users\\Mattia\\Anaconda2\\Library\\bin .

Do i have to set any other env veriables?

The problem is that you should not have either PYTHONPATH or PYTHONHOME set. They are both pointing to a non-Continuum version of Anaconda, I believe. Anaconda will install (by default) into a directory called Anaconda , either at C:\\Anaconda or at C:\\Users\\USERNAME\\Anaconda (IIRC). It is generally recommended that you should not ever set PYTHONPATH or PYTHONHOME , except as a last resort, exactly because of these kinds of problems.

You can see which Python interpreter you're running by doing:

>>> import sys
>>> sys.executable

And then you can see what directories are ending up in your Python library path (where import statements will look for packages, such as scipy and numpy ) by doing one of the following:

>>> import sys
>>> sys.path

or the more readable version:

>>> import sys
>>> for p in sys.path:
...    print p

As pointed out by @Mr.F the error was given by the presence of the PYTHONPATH and PYTHONHOME . Deleting them i was able to use the Anaconda version of python.

If you have module not found error, you may need to launch python from anaconda terminal using "python" instead of the shortened "py". I had my module installed properly, but spent forever trying to fix it because of this. Apparently py does not launch the anaconda activated or anaconda base environment, but launches another version of python.

尝试再次安装scipy

conda install numpy scipy

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