How to Install Setup Tools for Python on Linux?
Python comes in two versions: Python v2.x and Python v3.x. (Here, x represents an appropriate version number.) While Python v2.x is a legacy branch and has better library support, Python v3.x is the future of Python. Most Linux distributions and Mac OS X operating systems are equipped with Python, and they have v2.x as their preferred and default version of Python. We will be using Python v2.7 as the default version of Python for the rest of the book due to the following reasons:
- It is the most current version of the Python v2.x branch.
- It has large community support, and solutions for its known issues are available through support forums.
- It is supported by most of the major Python libraries.
Even though the code samples, exercises, and projects provided in this book should work in any variant of Python 2.7.x, it's better to have the latest version.
Installing Python
Your fondness for an operating system is developed due to multiple factors, and you can never ignore someone's bias towards a particular OS. Thus, this book provides installation and configuration guidelines for three of the most popular operating systems: Linux, Mac OS X, and Windows. Let's begin by configuring Python for a Linux computer.
Linux
The majority of Linux distributions come with Python preinstalled. To check the latest version of the installed Python, use the following command at the terminal window:
Code:
$ python -V
Make sure that you are using an uppercase V as the option for the previous command. Once you execute it on the terminal, it will print the complete version number of your current Python installation if the version is 2.7.x, you are good to go, and your Linux is updated with the latest version of Python that is required for this book. However, if you have any version that is less than or equal to 2.6.x, you will need to first upgrade Python to the latest version. This process will require root privileges, as Python will be installed as a system component that will replace the previous versions.
Ubuntu
If you are using Ubuntu 11.10 or later versions, you should already have Python v2.7.x installed on your machine. You can still upgrade Python to the latest revision of v2.7.x using the following command:
Code:
$ sudo apt-get update && sudo apt-get --only-upgrade install python
Output:
Hit:1 http://in.archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Get:4 https://dl.google.com/linux/chrome/deb stable InRelease [1,825 B]
Get:5 https://brave-browser-apt-release.s3.brave.com stable InRelease [7,547 B]
Get:6 https://dl.google.com/linux/chrome/deb stable/main amd64 Packages [1,082 B]
Get:7 https://brave-browser-apt-release.s3.brave.com stable/main amd64 Packages [8,925 B]
Get:8 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages [1,050 kB]
Get:9 http://in.archive.ubuntu.com/ubuntu jammy-backports InRelease [109 kB]
Get:10 http://in.archive.ubuntu.com/ubuntu jammy-updates/main i386 Packages [547 kB]
Get:11 http://security.ubuntu.com/ubuntu jammy-security/main i386 Packages [383 kB]
Get:12 http://security.ubuntu.com/ubuntu jammy-security/main Translation-en [200 kB]
Get:13 http://security.ubuntu.com/ubuntu jammy-security/restricted amd64 Packages [1,226 kB]
Get:14 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [1,262 kB]
Get:15 http://in.archive.ubuntu.com/ubuntu jammy-updates/main Translation-en [259 kB]
Get:16 http://security.ubuntu.com/ubuntu jammy-security/restricted Translation-en [200 kB]
Get:17 http://security.ubuntu.com/ubuntu jammy-security/universe i386 Packages [577 kB]
Get:18 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 Packages [815 kB]
Get:19 http://in.archive.ubuntu.com/ubuntu jammy-updates/restricted amd64 Packages [1,250 kB]
Get:20 http://in.archive.ubuntu.com/ubuntu jammy-updates/restricted Translation-en [203 kB]
Get:21 http://in.archive.ubuntu.com/ubuntu jammy-updates/universe i386 Packages [675 kB]
Get:22 http://in.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [1,018 kB]
Get:23 http://in.archive.ubuntu.com/ubuntu jammy-backports/main i386 Packages [33.9 kB]
Get:24 http://in.archive.ubuntu.com/ubuntu jammy-backports/main amd64 Packages [41.7 kB]
Get:25 http://in.archive.ubuntu.com/ubuntu jammy-backports/universe i386 Packages [13.4 kB]
Get:26 http://in.archive.ubuntu.com/ubuntu jammy-backports/universe amd64 Packages [24.3 kB]
Fetched 10.1 MB in 1min 28s (115 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package python is not available but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
If you are running an older version of Ubuntu (such as 10.04 or older), you should have 2.6 as the default version. In this case, you will need to run the following set of commands to install version 2.7:
$ sudo add-apt-repository ppa:fkrull/deadsnakes
$ sudo apt-get update
$ sudo apt-get install python2.7
The first command will add an external Ubuntu repository, which will allow you to install any version of Python. The next command will update and index the list of available packages.