Upgrading Python 2 to 3


Keeping up-to-date on your code can be complicated, especially if it’s something you aren't super familiar with. However, the upgrading process of python2 to python3 is pretty straightforward and easy to do. Ready? Then let’s jump right into upgrading Python 2 to 3.


First off, make sure your ubuntu version is up to date with ubuntu18.04 with the command below:

lsb_release -a

Updating The Instance Python Version from py2 to py3

If your instance is already on 18.04 python3 should already be installed by default. Try running python3 -V to check if it's there and what version you’re running. If it doesn't exist for whatever reason on your system just run:

sudo apt install python3

To make it so that you don't have to type 'python3' for when you use python, put this into the '~/.bashrc or '~/.bash_aliases' file:

alias python=python3

Updating your virtual Environment's Python

The simplest answer to this is that you can't update it. Instead, you have to remake the virtual environment with the specified python version that you want.

This is how I "updated" ARChive from python2 to python3 besides just updating the code with the proper syntax for each module and so on.

Below are the commands to install the virtual environment and then create said environment:

sudo apt-get install python-virtualenv
sudo virtualenv -p python3.x
source /bin/activate

After you've done that you can use the environment however you see fit with an updated python.


There you have it! A quick and easy way to upgrade Python 2 to Python 3. If you get wrapped up in any complications though, just reach out to us and we’ll help you get unwrapped. 😉

Leave a Comment