Installing Python 3.6.2 on WSL – smallsec

Installing Python 3.6.2 on WSL

September 07, 2017

I’ve been doing a lot of Python work lately. Since I’ve got a couple of young kids that keep me busy, I have to sneak time on the laptop upstairs. It’s a Mac so most Linux-y things work as you’d expect.

Sometimes, though, my wife wants to use her computer and I’m relegated to Windows in the basement. Unfortunately, the tool I’m building needs readline, which isn’t available on Windows, and pyreadline was throwing errors. I’d dabbled a bit with WSL and had been really impressed with how well it works so I decided to give it a shot.

And then I realized that I’d used f-strings throughout, which were brought in with Python 3.6, and Ubuntu 16.04 LTS uses 3.5.2, so down the rabbit hole we went.

Here’s what you need to do to get Python 3.6.2 and virtualenv running in bash on Ubuntu on Windows.


First we start with the bits. Python 3.6 isn’t available through apt, so you’ll need to add a ppa first:

sudo add-apt-repository ppa:jonathonf/python-3.6

Next, update and install Python3

sudo apt update
sudo apt install python3.6 python3-pip

Python Configuration

Python3 by default will be 3.5.2, which won’t do.

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2

You can then toggle between the two using sudo update-alternatives --config python3. Once you’ve finished getting virtualenvwrapper sorted, you can change back to 3.5.

virtualenv Configuration

Next, we’re going to upgrade pip because OCD and install virtualenv and virtualenvwrapper.

sudo -H pip3 install --upgrade pip
sudo -H pip3 install virtualenv virtualenvwrapper

Edit your ~/.bashrc

export WORKON_HOME=$HOME/.virtualenvs                    # Environments stored here
export PROJECT_HOME=/mnt/c/Users/<username>/Code         # Path to your Python projects
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.6       # Make Python3 the default
source /usr/local/bin/               # Engage!

Finally load all the goodies with source ~/.bashrc.


I like workon <environment name> to dump me in the project directory. To do this, add the following to ~/.virtualenv/postactivate