Need to have 2 versions of Python without using a VM

I need to have 2 versions of Python installed on my PC. The first must be the latest version in order to use youtube-dl, and the second must be the 2.7 version for a course that says we must not upgrade to get the same results.

I'm on Ubuntu 12.04. How can I have two different versions of Python without using virtual machines?


Solution 1:

You can just install them alongside eachother.

sudo apt-get install python2.7 python3

I think by default Python 2.7 will be used (i.e. is symlinked to /usr/bin/python). You can change this by changing that symlink. Most Python programs will specify which version they need and use it automatically.

Changing the symlink is not advised, as it is likely to cause programs to return errors.

Solution 2:

Look into virtualenv. You can install multiple versions of python, each in their own virtual environment, and then activate the one you want to use. Inside the virtual environment, you can install other tools as well.

virtualenv info

Here's another Stack Overflow thread on this