2

I just issued the following commands successfully:

conda install python=3.7.2
conda update python

But when I give the following command:

python -V

I still get:

Python 2.7.10

I don't understand why? Is there a way to make this Conda environment use python3 by default? Because right now if I type python it starts the Python 2 interpreter. I can run Python 3 by typing python3 but I'd rather have Python 3 as the default.

merv
  • 67,214
  • 13
  • 180
  • 245
mcrepeau
  • 23
  • 2
  • 5
  • This happend becouse you have installed both versions. – Tazo leladze Mar 03 '19 at 19:24
  • You may want to check [this answer](https://stackoverflow.com/a/44711567/570918) to a similar question. Upgrading Python is not straightforward. Conda is coupled to it, and so you need to follow the Anaconda guidance to first decouple. Otherwise it can seriously break your entire Conda installation. – merv Mar 03 '19 at 20:08
  • 1
    There is clearly something I'm not understanding here. I just issued this command: `conda create --name python37 python=3.7.2` followed by this command: `conda activate python37` and still when I enter this command: `python -V` I get Python 2.7.10. Why can't I create a simple python 3 environment? – mcrepeau Mar 03 '19 at 21:02
  • Okay, so it turns out the python 2.7.10 was not part of a conda environment. It was a python version I installed long before I ever installed anaconda. It was in `/opt/local/bin`. I moved it out of there and now when I am in my conda environment and type `python -V` I get `Python 3.7.2`. Of course, when I am *not* in a conda environment (i.e. after `conda deactivate`) typing `python` results in `-bash: /opt/local/bin/python: No such file or directory` so this is not an ideal solution. – mcrepeau Mar 03 '19 at 22:26
  • 1
    The problem was that somehow a copy of python 2.7.10 was installed in `/opt/local/bin` where it doesn't belong (there should only be the copy that comes with MacOS, installed in `/usr/bin`). Because `/opt/local/bin` was before the anaconda directory in my $PATH the 2.7.10 version was always found first. Once I removed it from `/opt/local/bin` I got the expected behavior: with conda activated command `python` launches the anaconda python (3.7.2) and with conda deactivated command `python` launches the 2.7.10 python in `/usr/bin` – mcrepeau Mar 04 '19 at 00:57

0 Answers0