I've got the next couple of weeks off school, so I'm using the time to dig into some of the tech stuff I haven't had the time to get to through the year. The first thing on that list is Python.

I've played with Python before, but only minimally. However, since I've recently become interested in machine learning and data science, it's come up a lot more often: it's the language of choice in that field (along with R). My biggest hurdle for getting into Python was the multiple versions: I probably didn't give it enough time, but I couldn't figure out how to properly juggle different versions of Python and their packages. I guess I'm spoiled by the ease-of-use that tools like rbenv or npm give me.

Anyway, I finally buckled down and figured it out. If you're on a Mac and have a similar issue, you might find this helpful.

You'll start with the version your Mac ships with (probably 2.7.5 for me, but it doesn't matter). First, you'll install pip, by downloading get-pip.py and running it. Now, with pip, you can install virtualenvwrapper; this will also install the main tool virtualenv, which is, of course, a dependency of virtualenvwrapper:

pip install virtualenvwrapper

Next, some lines for your .<shell>rc file. The exact file will depend on your shell and setup: if you're using bash, they should end up in .bashrc. Using zsh? .zshrc. And so on:

export WORKON_HOME="$HOME/.virtualenvs"
source /usr/local/bin/virtualenvwrapper.sh

Now, you can install whatever versions of Python you want, however you want. I prefer to use homebrew, which has packages for several versions (brew search python).

brew install python3

To create a virtual environment, you can do this:

mkvirtualenv <name>

If you want this environment to use a version of Python, use the -p flag and the path to the executable:

mkvirtualenv <name> -p `which python3`

Now, inside the environment, the command python is remapped to whatever version you chose: no need to write python3, python28, and so on. To use a virtual environment, use workon <name> to "move into" the environment. From "inside" the environment, you can use pip install <package> to install packages. Of course, they'll be contained in that environment. To leave an environment, just run deactivate. Or workon <other-name> to move directly to another different environment.

I'm nowhere near being a Pythonista, but I hope this works for you. For other virtualenvwrapper commands, check out the documentation.