Managing Multiple Versions of Python

Thu Sep 13 2018


This seems about right. Since I’m currently taking the AI4R course, I find myself having to switch between Python 2 and Python 3 on a daily basis. Since I’m on a Mac, that means I also have the version of Python that came with it (which I never use).

I manage most of my installs with Homebrew, so that solves getting the latest and greatest Python 3, but how to I manage the multiple versions I need to use?

You can do some Googling and get lots of choices.

I just use Conda to do it for me.

First, install Conda. I’ll do it from Homebrew, obviously.

brew cask install anaconda

From there, I can create different environments for the different versions of Python I need to use. I’ll create one named “ai4r” and choose to install Python 2.7 for that environment.

conda create -n ai4r python=2.7

There you have it. I now have a separate environment with the specific Python version I need for the course. I just have to switch to it whenever I need it.

source activate ai4r

And when I need to change it back, I can just activate the “base” environment:

source activate base

If you found the post helpful and would like this same content delivered to you,

Subscribe to my newsletter