Monday, January 2, 2017

How to install python from source in Debian/Ubuntu

There are multiple ways of installing python in Linux. First you can just install it from your distro repository, for example in Debian you need to use these commands (depending on which version do you need):
sudo apt-get install python2.7
sudo apt-get install python3

Downside of this approach is that the version is not the latest. To install the latest version, you would need to download it from python.org and install from source. Below I will show you how to do it for python2.7.

1. Dowload python2.7 from python.org and extract files from archive:
wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz
tar -xf Python-2.7.13.tar.xz

2. If you don't have build tools, install it:
sudo apt-get install build-essential

3. Change directory to where you've extracted your files:
cd Python-2.7.13

4. Configure it by entering this command:
./configure

Installation


Let's consider 3 different ways of installing python from source. You can choose any of them, depending on your needs.

5.1 To install it system wide, as default python, use command:
sudo make install
To access python in this case, simply type python and press ENTER.

5.2 To install it system wide, as an alternative python version (your original python will not be modified):
sudo make altinstall
In this case, python should be accessable at /usr/local/bin/python2.7

5.3 To install it to a custom location (e.g. ~/python2.7/), you can use:
make altinstall prefix=~/python2.7
In this case, python can be run as ~/python2.7/bin/python2.7


No comments:

Post a Comment