3

I have created an environment for a specific Python version using

conda create --name my_env python=3.6

when I list all the environments using conda env list I get a correct list of environments:

# conda environments:
#
base        /opt/anaconda
my_env      /opt/anaconda/envs/my_env

Inside /opt/anaconda/envs/my_env/bin/ there is python interpreter, which, as expected, has version 3.6. When I activate the environment

source activate my_env

it successfully activates (i.e. the terminal prompt indicates (my_env)).

However, when I try to check the python interpreter to which I am currently pointing, which python gives me:

/opt/anaconda/bin/python

which belongs to base environment, instead of

/opt/anaconda/envs/my_env/bin/python

which I would expect.

Question: Why did that happen? More importantly, how to change the Python interpreter path to which the environment points? I.e. in this case I'd like which python to point to /opt/anaconda/envs/my_env/bin/python after activating my_env.

Tomasz Bartkowiak
  • 12,154
  • 4
  • 57
  • 62
  • 1
    Which version of conda are you using? – Iain Shelvington Jan 05 '20 at 12:14
  • 1
    With me it works as expected. My conda version is 4.7.12 – KenHBS Jan 05 '20 at 12:14
  • "conda activate and conda deactivate only work on conda 4.6 and later versions" - https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands – Iain Shelvington Jan 05 '20 at 12:15
  • Hi guys, thank you for your quick response. It was actually my mistake and you correctly spotted that reproducing the steps mentioned in the question should result in an expected interpreter used (i.e. `Python 3.6`). This is because I was activating the environment using `source activate my_env` not `conda activate my_env` (unlike stated in the question) which resulted in wrong interpreter used. I updated the question accordingly. PS after few more trials `source activate my_env` results again in expected, proper Python interpreter, not quite sure why is that. – Tomasz Bartkowiak Jan 05 '20 at 12:38
  • Also the general question about being able to change the path of the Python interpreter inside the environment still holds I believe. I have not managed to find relevant documentation or similar question on SO. – Tomasz Bartkowiak Jan 05 '20 at 12:42
  • 1
    I don't think you want to change the path of the Python interpreter in an environment. `conda activate` handles all of that for you. What situations would you want to change the path to the Python executable? – darthbith Jan 06 '20 at 03:02
  • @darthbith Unfortunately I can no longer reproduce the error. The issue was that, after environment activation,`which python` was returning the path to the `base` environment (even though the terminal prompt showed the name of the proper environment). Will try to have a closer look and try to reproduce. – Tomasz Bartkowiak Jan 06 '20 at 19:04

1 Answers1

0

You could try:

conda uninstall /opt/anaconda/bin/python
William Baker Morrison
  • 1,642
  • 4
  • 21
  • 33