0

Can different python versions co-exist on the same machine

/usr/bin/python --version
Python 2.7.2+

I currently have the above version, how do I also have the latest python installed locally for the same Ubuntu OS user.

Joe
  • 14,513
  • 28
  • 82
  • 144

5 Answers5

2

You can simply install the latest version of Python using the inbuilt package manager. It should not overwrite the existing version. Take a look at this picture. It demonstrates the packages available to Mint Linux (based on Ubuntu), and shows that it's possible to install both using the default package manager.

Synaptic Package manager

You can then simply call Python3 directly to run the new version.

e.g.

Python3 test.py

You could also do the same for the old version.

Python2.7 test.py

If you want to make sure that your script is running the correct version you can add the following shebang line to your scripts.

#!/usr/bin/env python3
eandersson
  • 25,781
  • 8
  • 89
  • 110
  • 1
    Feel free to leave a comment when downvoting. This is at least how I run multiple Python packages on my Ubuntu installation. – eandersson Jan 15 '13 at 10:30
2

Yes, they can. Quite easily.

As an Ubuntu user, you can install python3 from apt, aptitude or the new Software Center application. This will install it globally for all users.

To install your own custom version of Python, first make sure you have a proper build environment available. Install build-essentials.

Download the source of the version of Python you want to play with, and extract it.

Run configure with ./configure --prefix=/home/yourusername/python/2.xx replace xx which whatever version it is that you need, then run the normal make, followed by make install.

Now, when you want to use this custom version of Python, or install any packages to it - you need to call it directly:

Like this:

/home/yourusername/python/2.xx/bin/python setup.py install --prefix=/home/yourusername/python/2.xx

If all that seems a bit much, you can use pythonbrew, a tool inspired by rvm and brew. It automates most of the tasks and allows for easy switching between Python versions.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
1

you can have multiple versions of python on the same machine. You can install in different directories (configure while install) to keep mutiple versions. though the "python" command will only link to one version but you can run using the full command i.e. python2.7 or python2.6. Alternatively if you have a executable script, you can define which version to use

 #! /usr/bin/env python2.6 

or

`#! /usr/bin/python2.6  # where ever it is installed`.

as the first line of your executable script

pranshus
  • 187
  • 6
0

At least for my installation there is also the python3 package. The binary has the same name.

python3 --version
Python 3.2.3

If you mean by coexist, that you can have both installed, the answer is yes.

If you want a custom installation, the details might be messy, especially if you want both installed versions to use the same packages (which is quite impossible for many as the ABI has changed).

Constantinius
  • 34,183
  • 8
  • 77
  • 85
0

You may check this out. RVM is ruby's tool enables what you are looking for python

Is there a python equivalent of Ruby's 'rvm'? :

Yes, it is virtualenv along with virtualenvwrapper.

update: you may install both at once with virtualenv burrito.

Community
  • 1
  • 1
0x90
  • 39,472
  • 36
  • 165
  • 245