6

I currently have python3 set as my default python version but I'd like to be able to switch back to python2 for certain things so I created a conda environment with the following command:

conda create -n py2 python=2.7

and then activated it with:

source activate py2

but when I do:

python --version

I still get

Python 3.6.8

What am I doing wrong here? I'm trying to download a conda package this is only python2 compatible but despite being in a python2 environment, it keeps telling me my python version is incompatible.

nickeener
  • 61
  • 1
  • 4
  • 1
    Is the command to activate not `conda activate py2`? It would help us if you edited the post to include the result of `which python` executed after you activate py2. – brentertainer Aug 03 '19 at 18:26
  • 1
    I believe `source activate` and `conda activate` are interchangeable. Before activating, `which python` returns `/home/nickeener/anaconda3/bin/python` and after activating it returns `/home/nickeener/anaconda3/envs/py2/bin/python`. – nickeener Aug 03 '19 at 18:41
  • Maybe this changed between versions, but ones you created a environment in conda shell, you do "conda env list" to see the new env, then you say "activate py2" and py2 should appear at the left, then you do "conda list" which shows you all installed packages including python version. – lmielke Aug 03 '19 at 20:47
  • Does the output of the `create` command show that the environment is created with Python 2? Also, you should definitely be using `conda activate` nowadays – darthbith Aug 04 '19 at 20:35
  • Try `which -a python` to make sure that you're picking up the Python from your Anaconda environment. – Roland Weber Aug 05 '19 at 07:15
  • @RolandWeber Hi. `which -a python` gives `'which' is not recognised` error. I did `conda create -n py366 python=3.6.6` bu when I activate `py366` and do `python --version` I get `Python 3.6.9` which is the same as my root. How to find out what version of python is used in conda environment? Thank you – Confounded Nov 01 '19 at 14:08

1 Answers1

2

You might be running into the issue where you have multiple environments on top of one another.

Try running:

conda deactivate

multiple times in order to exit from all of the environments. Then run:

condo activate py2