Search code examples
pythonanacondaenv

anaconda virtual env imports modules from global


Working in Windows PowerShell, I created a virtual environment within Anaconda using

>create conda -n test python=2.7.8

I activated it using

>activate test
activating environment "test"...

The test env contains no packages. Python is the only thing in there. I checked the test\Lib\site-packages folder and it is empty. I started python

>python
>>>import pandas
>>>pandas.Series(range(1,5))
0  1
1  2
2  3
3  4
dtype: int64

I expected error messages because there is no pandas installed in this virtual env. Instead it seems to be importing pandas from the global Anaconda environment, where pandas is installed.

I thought virtual environments were supposed to be isolated. Have I misunderstood how they are supposed to work? If they are supposed to be isolated, what might the problem be?


Solution

  • New to stack overflow, but I think I can help. First, the commands I needed to run were a bit different (I am on Linux). That is, in fact, how virtual environments are supposed to work. A few things to try: conda create --dry-run -n test python=2.7.8 to see if pandas is being installed to the venv (I don't know why it would). Another idea, when you activate test does the prompt actually change to the venv? Maybe see: virtualenv-in-powershell