5

I have created an anaconda environment. When I activate the environment I can see that the environment is using a different Python version than my default Python version. This is correct. However, when I check python path within the activated environment.

import sys
from pprint import pprint
pprint(sys.path)

I can see that the first 4 items are pointing to the default Python installation.

['', 'C:\\Python27\\Lib\\site-packages\\distribute-0.6.35-py2.7.egg', 'C:\\Python27\\Lib\\site-packages\\ipython-1.0.0-py2.7.egg', 'C:\\Python27\\Lib\\site-packages', 'C:\\Python27\\Lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info', 'C:\\Users\\sennn\\AppData\\Local\\Continuum\\Anaconda32\\envs\\apiapi\\python27.zip', 'C:\\Users\\sennn\\AppData\\Local\\Continuum\\Anaconda32\\envs\\apiapi\\DLLs', 'C:\\Users\\sennn\\AppData\\Local\\Continuum\\Anaconda32\\envs\\apiapi\\lib', 'C:\\Users\\sennn\\AppData\\Local\\Continuum\\Anaconda32\\envs\\apiapi\\lib\\plat-win', 'C:\\Users\\sennn\\AppData\\Local\\Continuum\\Anaconda32\\envs\\apiapi\\lib\\lib-tk', 'C:\\Users\\sennn\\AppData\\Local\\Continuum\\Anaconda32\\envs\\apiapi', 'C:\\Users\\sennn\\AppData\\Local\\Continuum\\Anaconda32\\envs\\apiapi\\lib\\site-packages', 'C:\\Users\\sennn\\AppData\\Local\\Continuum\\Anaconda32\\envs\\apiapi\\lib\\site-packages\\PIL', 'C:\\Users\\sennn\\AppData\\Local\\Continuum\\Anaconda32\\envs\\apiapi\\lib\\site-packages\\Sphinx-1.2.3-py2.7.eg g', 'C:\\Users\\sennn\\AppData\\Local\\Continuum\\Anaconda32\\envs\\apiapi\\lib\\site-packages\\win32', 'C:\\Users\\sennn\\AppData\\Local\\Continuum\\Anaconda32\\envs\\apiapi\\lib\\site-packages\\win32\\lib', 'C:\\Users\\sennn\\AppData\\Local\\Continuum\\Anaconda32\\envs\\apiapi\\lib\\site-packages\\Pythonwin', 'C:\\Users\\sennn\\AppData\\Local\\Continuum\\Anaconda32\\envs\\apiapi\\lib\\site-packages\\runipy-0.1.1-py2.7.eg g', 'C:\\Users\\sennn\\AppData\\Local\\Continuum\\Anaconda32\\envs\\apiapi\\lib\\site-packages\\setuptools-5.8-py2.7. egg']

This creates a problem of importing wrong versions of some of libraries.

Why these default directories have been added to the path? Is this a default behavior when creating a new Anaconda environment? Is there any way to overwrite it?

Bakuriu
  • 98,325
  • 22
  • 197
  • 231
LLaP
  • 2,528
  • 4
  • 22
  • 34
  • I encountered a similar issue on a Windows machine after installing PyCharm. From PyCharm I changed the interpreter to use the one I installed myself and I was able to access the old libraries. – Radu Gheorghiu May 26 '15 at 11:03
  • You can install Anaconda inside a virtualenv to have a confined environment – Below the Radar May 26 '15 at 12:25
  • Anaconda in some respect provides a virtual environment, therefore wrapping it inside a virualenv doesn't make much sense to me. – LLaP May 26 '15 at 12:32

1 Answers1

5

Check to see if you have the environment variables PYTHONPATH or PYTHONHOME set. conda info -a will also show you all the relevant environment variables that might cause this sort of thing to happen.

asmeurer
  • 86,894
  • 26
  • 169
  • 240
  • PYTHONHOME is not set, and PYTHONPATH is set to C:\Python27\Lib\site-packages. Is this info referring to system or general anaconda installation wise variables? – LLaP May 27 '15 at 21:07
  • 2
    `PYTHONPATH` being set is the cause of the issue. It's probably a system-wide environment variable. I recommend unsetting it, as it will cause the Anaconda Python and any conda environment to pick up those Python modules. Google how to unset environment variables in Windows (the procedure is a little different depending on what version of Windows you are using). – asmeurer May 27 '15 at 22:51
  • I've unset the PYTHONPATH variable and it's working fine now (I can only see Anaconda specific paths within the environment). I hope removal of this variable won't affect my standard Python environment. It would be nice if i could simply change configuration of Anaconda to omit this system variable rather than relying on the system variable being set or not. – LLaP May 28 '15 at 07:21
  • 2
    Your standard Python should still point to itself. Every Python installation, whether it be the standard Python install or a conda environment, will include its own site-packages in its sys.path automatically. PYTHONPATH is only needed if you want to add a different location than the standard ones to the sys.path. Anaconda isn't going to be changed to ignore the variable because there are legitimate use-cases for it. – asmeurer May 28 '15 at 15:48
  • @asmeurer: Great answer. Would you mind looking at this? http://stackoverflow.com/questions/36733179/why-conda-cannot-call-correct-python-version-after-activating-the-environment#36733234 – neversaint Apr 20 '16 at 05:39