C.R.A.W.LAB Etouffee

Delicious Bytes of Information

The Move to Python 3

One of the reasons that I switched to the Anaconda Python distribution in my lab is the the package manager Conda. This semester, I decided it was time to move my lab's work to Python 3. However, I wanted to keep my default Python 2.7 environment around during the transition. Conda makes it easy to do so.

Before beginning, its best to make sure conda has the most recent information about the repositories.1 To do this, update conda itself by:

$ conda update conda

Before making any changes, we'll first create a clone of your Python 2.7 root/main environment. To do so, issue the command:

$ conda create --name py2p7 --clone root

This command creates a named environment (the --name flag) named py2p7 that is a clone (--clone) of the root environment. This allows you to switch to this environment if you encounter some piece of code or a library/module that is troublesome to update to Python 3. To change your active environment to the one created above:

$ source activate py2p7

To switch back to the root environment (the one we'll be updating to Python 3):

$ source deactivate

Back in the main, root environment, we'll first install Python 3:

$ conda install python=3

Then, update the Anaconda itself. It should pull the Python 3 versions once it "sees" that you have Python 3 installed:

$ conda update Anaconda

You can check that you have the Python 3 versions of modules installed by Anaconda by:

$ conda list

You should get a long screen of text that looks something like:

Screenshot Showing py34_0 Versions

Notice that the last column is or ends with py34_0 for most of the entries. This indicates that the Python 3.4 version is installed and being used.


  1. All of the commands shown here should be issued at the terminal prompt, indicated by the $. You do not need to type the $