Python: modul not found after Anaconda installation

29,131

Solution 1

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

Solution 2

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.

Share:
29,131

Related videos on Youtube

tia_0
Author by

tia_0

Actuarial science student and data science passionate. Based in Italy, i'm writing my thesis on sentiment analysis and text mining appliend on the insurance sector. I mainly use R, but i used to program in C/C++, Java and in the glorious x86 Assembly. I learned my programming language basics in high school and now, with the help of SO, i'm becoming better coder and i found myself ready to solve others problems.

Updated on May 21, 2021

Comments

  • tia_0
    tia_0 almost 3 years

    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?

    • phi
      phi over 7 years
      What is in your $PATH variable? (Try "echo $PATH")
    • tia_0
      tia_0 over 7 years
      I've edited my question
    • Mr.F
      Mr.F over 7 years
      Did you try it without modifying PYTHONPATH and PYTHONHOME?
    • tia_0
      tia_0 over 7 years
      Thanks, this solved the problem because now i see the Anaconda version in the python prompt.
  • Jacksonkr
    Jacksonkr almost 7 years
    Ahh! This took me FOREVER. I had to delete export PYTHONPATH=/usr/lib/python2.7:$PYTHONPATH from my ~/.bash_profile (for osx)
  • Atheer
    Atheer about 3 years
    Can you please elaborate? I printed the path, and I see it includes the directory the module is installed in yet it says Module not found!
  • phi
    phi about 2 years
    This helped, I needed to do unset PYTHONPATH then everything worked fine for me using the conda base environment. I tried to run a custom installed python module.