This is the second part in a series about installing multiple versions of Python. The main article which describes why this is necessary for development and testing, or to upgrade back-level os-provided versions is here.
Multiple versions can be installed globally via a package manager like apt-get or yum. Of all the options, this is the preferred method:
- The package manager can help keep the package current with security and other releases.
- Package manager installs handle dependency headaches better than compiling it yourself. Sometimes, far, far better.
Unfortunately, there are disadvantages as well:
- The user must have either sudo privileges or access to root.
- There's no ability to install locally to a user's home directory.
- Not all Python versions are readily available. For example, Ubuntu 12.04 currently comes with Python2.7 as default and also has version 3.3 available. If you want 2.4, 2.5, 2.6, 3.1, or 3.2 you're out of luck. At least in the official repo.
- An alternate install will add another version of python - without modifying the python executable, by adding a new executable with a version suffix (like python2.7). This is fine for scripts or programs that can be modified to reference the new version, or for scripts that can be run as an argument to the python executable, but won't work for all applications. Note also that this is not much of a problem if you're running your Python applications out of virtual environments - since each virtual environment will have a single version of Python.
- If you're thinking that this will allow you to install some modules (like matplotlib) via the package manager and have them work with your new alternate python - you're out of luck. They'll be installed in the site-packages directory of the primary python.
If you can use a Package Manager then this is absolutely the best way to go. And if the only thing holding you back is the lack of availability of the versions you want in the official repositories - then consider some unofficial repositories:
- For Ubuntu, consider using a PPA such as deadsnakes.
- For Redhat, consider using their Extra Packages for Enterprise Linux (EPEL)
- EPEL 5 (for Redhat 5, CentOS 5, etc - which comes with Python2.4 natively) has a package for 2.6, but there's no 2.5, 2.7, 3.3, etc.
- EPEL 6 (for Redhat 6, CentOS 6, etc - which comes with Python2.6 natively) has no Python packages available.