3

System: Ubuntu 16.04

Default result of python -V: Python 3.6.5 :: Anaconda, Inc.

Default result of which python: /home/myname/anaconda3/bin/python

I am trying to set up a virtual environment that uses python 2.7 while my default python is python 3.6 through Anaconda. However, after specifying the creation of a new environment from the terminal (conda create -n myenv python=2.7), my new environment still uses python 3.6.

A similar problem was addressed in these two questions:

Using conda to create virtual environment, I get the wrong version of Python despite specifying version. Why?

and

Why Conda cannot call correct Python version after activating the environment?

but my situation is not fixed by simply changing directories as was the case in those instances.

If I source activate myenv, python -V still gives me Python 3.6.5 :: Anaconda, Inc. even though which python does give /home/myname/anaconda3/envs/myenv/bin/python as expected. Going to this directory and typing ls -l says this is a pointer to python2.7, so I am not sure where the disconnect is between python -V and which python.

Any idea what is going on or how I can make an environment that actually uses python 2.7?

Thanks!

  • 1
    do you have Anaconda's Python 2.7 version installed? – Pedro Ferreira Nov 27 '18 at 18:14
  • I know my system has python 2.7 outside of Anaconda, which I had assumed would be what was accessed by Anaconda. How do I check if Anaconda has its own version of 2.7? – wanderingmathematician Nov 27 '18 at 18:22
  • I'm not sure if you can use your system's python with `conda create`. You can download the anaconda's 2.7 here https://www.anaconda.com/download/#linux – Pedro Ferreira Nov 27 '18 at 18:30
  • You can also try to use `virtualenv` (https://help.dreamhost.com/hc/en-us/articles/215489338-Installing-and-using-virtualenv-with-Python-2) if you don't need to use anaconda – Pedro Ferreira Nov 27 '18 at 18:33
  • 1
    @PedroFerreira It sounds like you are saying I need an entirely different installation of Anaconda to work with python2, but isn't (part of) the point of environments to be able to use different python versions? The answer to this question (https://stackoverflow.com/questions/24405561/how-to-install-2-anacondas-python-2-and-3-on-mac-os) says this is not necessary, but their solution did not work for me. – wanderingmathematician Nov 27 '18 at 18:48
  • you're right, I've tried the solution you showed me and you actually don't need a new Anaconda to work. I will try to think on a new solution – Pedro Ferreira Nov 27 '18 at 18:55
  • It's odd that the command `python` doesn't seem to be following my PATH. If I create a conda env with python 2.7, activate it, and go into /home/myname/anaconda3/envs/myenv/bin, `python` opens my default python 3.6. However, `./python` opens python 2.7. This is despite the fact that /home/myname/anaconda3/envs/myenv/bin is prepended to my PATH (I verified this). How is that possible? – wanderingmathematician Nov 27 '18 at 19:26
  • Perhaps it would be helpful to know how exactly anaconda environments are *supposed* to affect the path to accomplish a switch from one version of python to another. Then I could try to work backwards and see where things go wrong. Can anyone point me to an explanation of anaconda environment internals? – wanderingmathematician Dec 06 '18 at 22:05
  • I had the exact same problem. `which python` pointing at the correct miniconda env but `python` running a different one. I solved it by finding a forgotten `alias` in my `.bashrc` – EmmanuelM Apr 28 '21 at 08:35

0 Answers0