Python: modul not found after Anaconda installation
Question:
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:Python27Lib
.
EDIT : content of PATH
In my $PATH variable i have C:UsersMattiaAnaconda2
, C:UsersMattiaAnaconda2Scripts
and C:UsersMattiaAnaconda2Librarybin
.
Do i have to set any other env veriables?
Answers:
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.
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:UsersUSERNAMEAnaconda
(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
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.
Use
$ conda install package_name instead
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:Python27Lib
.
EDIT : content of PATH
In my $PATH variable i have C:UsersMattiaAnaconda2
, C:UsersMattiaAnaconda2Scripts
and C:UsersMattiaAnaconda2Librarybin
.
Do i have to set any other env veriables?
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.
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:UsersUSERNAMEAnaconda
(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
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.
Use
$ conda install package_name instead