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?

  • They're separate packages, you can have them both installed without doing anything special. Run python to get Python 2, or python3 for Python 3. Programs should use the right version automatically. – Thomas K Oct 6 '12 at 19:02
  • youtube-dl supports both Python 2 and 3. You don't need Python 3 to run the latest version of youtube-dl. – jfs Feb 7 '14 at 11:59

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.

| improve this answer | |
  • 7
    Personally, I would NOT recommend changing the /usr/bin/python symlink. Most Python 2 scripts use a #! /usr/bin/python hashbang, and changing the symlink will cause many of them to break. Use python when writing Python 2 scripts and python3 when writing Python 3 ones. – fouric Oct 3 '12 at 20:02
  • Right. I wouldn't do that, I'm just saying that you can and that that's how it works installing them side-by-side. – reverendj1 Oct 3 '12 at 20:28
  • Importantly, doing this will only get you Python 3.2 under 12.04. Currently, the newest version of Python is 3.3, and while this may be included in 12.10, it is included in the 12.04 repositories. – user802500 Oct 15 '12 at 19:56

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

| improve this answer | |

Many programs still use the older Python 2 whereas in Ubuntu 12.10 everything is slowly being ported over to the new Python 3 instead so that hopefully on release every program in the repository will use the newer version and you will only have that installed by default...

| improve this answer | |
  • Out of curiosity, where did you find out that plugins were being ported to Python 3? I thought that they were just going to leave them in 2 (although in hindsight that assumption seems silly). Can I get a list of the ones that have been ported and the ones that have not? – fouric Oct 3 '12 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.