321

I want to get the latest version of Python to use f-strings in my code. Currently my version is (python -V):

Python 3.5.2 :: Anaconda 4.2.0 (x86_64)

How would I upgrade to Python 3.6?

3
  • The second answer is, I think, the better answer, especially for those who have a "master"/"default" environment in which the latest and greatest is continually updated. Commented Feb 1, 2017 at 19:56
  • 1
    delete original env, create new env with the right python version with original name and re-run your installation script e.g. install.sh Commented Feb 15, 2021 at 21:26
  • Is it necessary for it to be tagged with macOS? Commented Feb 21, 2023 at 2:13

12 Answers 12

446

Anaconda had not updated Python internally to 3.6, but later versions of Anaconda has a Python 3.6 version here.

a) Method 1

  1. If you wanted to update, you will type conda update python

  2. To update Anaconda, type conda update conda

  3. If you want to upgrade between major python versions, like 3.5 to 3.6, you'll have to do

    conda install python=$pythonversion$
    

b) Method 2 - Create a new environment (the better method)

conda create --name py36 python=3.6

c) To get the absolute latest Python (3.6.5 at time of writing)

conda create --name py365 python=3.6.5 --channel conda-forge

You can see all this from here.

Also, refer to this for force upgrading.

Sign up to request clarification or add additional context in comments.

8 Comments

Unless Continuum have changed how conda operates, you cannot upgrade major Python versions by conda update python. See here: conda.pydata.org/docs/py2or3.html#update-or-upgrade-python
conda install python=$pythonversion$ e.g. conda install python=3.6
conda update python just took me from 3.6.5 to 3.7.0. Neat!
FYI method a) works for changing between different versions of python as well, as long as it doesn't break any dependencies within the venv
@fredrik conda update python bricked my conda installation.
|
40

Creating a new environment will install Python 3.6:

conda create --name 3point6 python=3.6

Output:

Fetching package metadata .......
Solving package specifications: ..........

Package plan for installation in environment /Users/dstansby/miniconda3/envs/3point6:

The following NEW packages will be INSTALLED:

    openssl:    1.0.2j-0
    pip:        9.0.1-py36_1
    python:     3.6.0-0
    readline:   6.2-2
    setuptools: 27.2.0-py36_0
    sqlite:     3.13.0-0
    tk:         8.5.18-0
    wheel:      0.29.0-py36_0
    xz:         5.2.2-1
    zlib:       1.2.8-3

3 Comments

If your conda installation is for Python 2.7 then conda create will create a 2.7 version. changing command to conda create --name 3point6 python=3 (adding =3 at the end) makes a python3 version.
It will indeed. I've changed my answer to specify python 3.6!
your solution makes me have to install all my old packages again from scratch. You should mention how to get around that. The title says upgrade so that is a sensible expectation for a good answer.
35

I found this page with detailed instructions to upgrade Anaconda to a major newer version of Python (from Anaconda 4.0+). First,

conda update conda
conda remove argcomplete conda-manager

I also had to conda remove some packages not on the official list:

  • backports_abc
  • beautiful-soup
  • blaze-core

Depending on packages installed on your system, you may get additional UnsatisfiableError errors. Simply add those packages to the remove list. Next, install the version of Python,

conda install python==3.6

which takes a while, after which a message indicated to conda install anaconda-client, so I did

conda install anaconda-client

which says it's already there. Finally, following the directions,

conda update anaconda

I did this in the Windows 10 command prompt, but things should be similar in Mac OS X.

1 Comment

page link now broken.
23

If you want to upgrade the Python version inside your existing environment, activate it first with conda activate <env_name> and then do:

conda install -c anaconda python=<version>

You might also need to update the dependencies with

conda update --all

3 Comments

This worked fine for me (upgraded from 3.6 -> 3.9 within an environment with many packages in it). Not sure what all the other complicated answers are for. Thanks.
Why -c anaconda? Isn't that the default?
@wjandrea yes -c is not necessary. So conda install python=3.12 works just fine.
22

In the past, I have found it quite difficult to try to upgrade in-place.

Note: my use-case for Anaconda is as an all-in-one Python environment. I don't bother with separate virtual environments. If you're using conda to create environments, this may be destructive because conda creates environments with hard-links inside your Anaconda/envs directory.

So if you use environments, you may first want to export your environments. After activating your environment, do something like:

conda env export > environment.yml

After backing up your environments (if necessary), you may remove your old Anaconda (it's very simple to uninstall Anaconda):

$ rm -rf ~/anaconda3/

and replace it by downloading the new Anaconda, e.g. Linux, 64 bit:

$ cd ~/Downloads
$ wget https://repo.continuum.io/archive/Anaconda3-4.3.0-Linux-x86_64.sh 

(see here for a more recent one),

and then executing it:

$ bash Anaconda3-4.3.0-Linux-x86_64.sh 

Comments

18

I'm using macOS v10.14 (Mojave).

These four steps worked for me.

  1. conda update conda
  2. conda install python=3.6
  3. conda install anaconda-client
  4. conda update anaconda

1 Comment

It works. It will use "flexible solve" when solving the environment. Thanks.
4

The only solution that works was creating a new Conda environment with the name you want (you will, unfortunately, delete the old one to keep the name). Then create a new environment with a new Python version and rerun your install.sh script with the Conda/pip installs (or the YAML file or whatever you use to keep your requirements):

conda remove --name original_name --all
conda create --name original_name python=3.8
sh install.sh  # Or whatever you usually do to install dependencies

Doing conda install python=3.8 doesn't work for me. Also, why do you want 3.6? Move forward with the world ;)


Note the below doesn't work:

If you want to update the Conda version of your previous environment you can also do the following (more complicated than it should be because you cannot rename environments in Conda):

  1. create a temporary new location for your current environment:

    conda create --name temporary_env_name --clone original_env_name
    
  2. delete the original env (so that the new env can have that name):

    conda deactivate
    conda remove --name original_env_name --all # Or its alias: `conda env remove --name original_env_name`
    
  3. then create the new empty environment with the Python version you want and clone the original environment:

    conda create --name original_env_name python=3.8 --clone temporary_env_name
    

Comments

2

This is how I manage to get (as currently there isn't any direct support. In the future, it will be for sure) Python 3.9 in earlier versions of Anaconda and Windows 10.

Note: I needed extra packages, so install them. Install only what you need

conda create --name e39 python=3.9 --channel conda-forge

Python 3.9 is available with later versions of conda. Use the below command:

conda create --name <myenv> python=3.9

And it will create your Python 3.9 virtual environment simply.

Comments

1

You can first remove the existing Python if any and then install the required version, sometimes directly installing the required version without removing the existing version causes compatibility issues.

conda activate your_env
conda uninstall python
conda install python=3.6

1 Comment

This method is useful for uninstalling and reinstalling another version with specific version of Python without changing the base Python version in the global environment
0
  1. Open an Anaconda PowerShell prompt as an administrator user.
  2. Type in conda update python.
  3. Wait about 10 minutes. In this process, you may need to type in y at some time.
  4. After completing, check your Python version in Conda by typing python --version
  5. If it is the newest version, then you can restart your computer.

Comments

0

From the anaconda website anaconda website. I got all the info I wanted to update Python version. To get the available Python versions.

conda search python

To create a new Python environment.

conda create -n py12 python=3.12 anaconda

To activate

conda activate py12

Comments

-1

If you want to preserve the specific versions of the packages currently in your environment, this is the best method I found (at the time of the answer):

source activate old_env
conda env export > old_env.yml

Then process it with something like this:

with open('old_env.yml', 'r') as fin, open('new_env.yml', 'w') as fout:
    for line in fin:
        if 'py35' in line:  # replace by the version you want to supersede
            line = line[:line.rfind('=')] + '\n'
        fout.write(line)

Then edit manually the first (name: ...) and last line (prefix: ...) to reflect your new environment name and run:

conda env create -f new_env.yml

You might need to remove or change manually the version pin of a few packages for which which the pinned version from old_env is found incompatible or missing for the new python version.

I wish there was a built-in, easier way...

If you don't mind possibly some changes of the version of the other packages of your environment, the other answers provides various ways to do it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.