138

I created a conda environment with Python version 3.8, but it doesn't support matplotlib... So I am looking for something like this to change the Python version: conda env my_env update to python=3.6. Is this possible or do I need to recreate the environment?

I have miniconda installed.

Alexander
  • 105,104
  • 32
  • 201
  • 196
elixirtrip
  • 1,483
  • 2
  • 6
  • 5
  • Thx for this question. Got an UnsatisfiableError on CUDA driver when I tried to install keras in a conda env with python 3.8. Changing to python v. 3.7 solved the issue. – arun Aug 14 '20 at 00:24

4 Answers4

227

Activate the relevant environment, then install your target python version.

conda activate my_env
conda install python=3.6
Alexander
  • 105,104
  • 32
  • 201
  • 196
  • 5
    Omg, it's so obvious... My only excuse is that I'm completely new to it. Thank you! – elixirtrip Dec 03 '19 at 18:53
  • 24
    I did this but still the version doesn't change – B.Quaink Dec 15 '20 at 16:12
  • 4
    @B.Quaink That sounds very unlikely. If true, please create a new post providing the exact steps you took (including OS) and then link back. – Alexander Dec 17 '20 at 04:42
  • 1
    I created a new environment and then set up the python version, that worked. Maybe the base(root) environment isn't changeable? I followed your steps above, it said it changed but when I started up python the newer version was still there. – B.Quaink Dec 22 '20 at 11:12
  • Yes, the base environment is based on the conda version downloaded. You first need to create a new environment before you can install another version of python into it. – Alexander Dec 22 '20 at 14:09
  • 1
    Restart your shell if the version does not change after doing this. – forgetso Apr 22 '21 at 11:19
  • 14
    I had to ```conda uninstall python``` then I could install a new version. Otherwise the version did not change for me. – Josiah Coad May 08 '21 at 00:30
  • Might need to uninstall the current python and then install the desired one... otherwise, you might get conflicts for some packages which are dependent to the current python. – inverted_index Jun 26 '21 at 02:17
  • 1
    are you sure this works? I run python and it still says 3.8.2... – Charlie Parker Sep 16 '21 at 23:00
  • @Alexander can you try 3.9? Perhaps that is the issue `conda install python=3.9` – Charlie Parker Sep 17 '21 at 00:24
  • @Alexander what does the `-n base` flag do? – Charlie Parker Sep 17 '21 at 16:50
  • why would `conda update conda` not be enough? (perhaps this is my issue) – Charlie Parker Sep 17 '21 at 16:52
  • Everytime I update python, then I find myself in conda-conflict-hell after which point you have to steadily delete packages until the install finally works and then you can reinstall. I've had the most success by first removing python_abi and then some graphics packages, e.g. remove "xz" and it'll knock out a lot. – Tunneller Mar 15 '23 at 15:04
27

Adding to the answer above

conda activate my_env
conda uninstall python
conda install python=x.x
jacktim
  • 420
  • 4
  • 11
  • Any explanation for uninstall and reinstall python instead of just upgrade it? – EMT Feb 23 '22 at 10:10
  • 1
    Not in particular, the existing solution didn't work for me and this did so felt like sharing :). I would imagine upgrade would work too – jacktim May 13 '22 at 09:52
  • This caused me to lose all my packages, might as well create a new environment – Jeff Bezos Jan 31 '23 at 20:14
  • @JeffBezos Some preliminary research suggests that should not be the case https://stackoverflow.com/questions/11248073/what-is-the-easiest-way-to-remove-all-packages-installed-by-pip#:~:text=%40patelshahrukh%20uninstalling%20python%20DOES%20NOT,that's%20more%20work%20to%20fix. I will test it though - if it does I will update the answer to make people aware. – jacktim Feb 01 '23 at 21:09
4

Rebuild a new environment, for example called "myenvi"

conda create --name myenvi python=3.6

And make sure the version by

python --version

After installing all packages, double-check with

conda list -n myenvi
Zhang Jian
  • 115
  • 1
  • 2
  • 22
    While your way solves the problem, the OP asked for a way that would allow them to keep the existing environment. So, this answer does not really help here. – kyriakosSt Nov 15 '20 at 15:37
2

If you already have existing python installation may be in other environment, you can simply use it as base.

Here's what you need to do:

conda activate base
conda install python=3.6

Note: This will activate root environment. and python 3.6 already installed, it will simply replace it.

Gray Programmerz
  • 479
  • 1
  • 5
  • 22