
Python is a high-level, interpreted programming language that has gained significant popularity over the years due to its simplicity and versatility. However, within the Python community, there has been a long-standing debate between Python 2 and Python 3. This is particularly noticeable in Ubuntu, where Python 2.7 is still the default version. In this article, we will delve into the reasons behind this decision and discuss the ongoing transition to Python 3.
Python 2.7 is still the default in Ubuntu due to the large amount of legacy Python 2 code still in use. However, Ubuntu has been actively encouraging developers to transition to Python 3, and newer releases provide options to make Python 3 the default version.
Historical Background
Python 2.7 has been the default Python version in Ubuntu for a long time. This is largely because many developers and applications still rely on it. However, Python 2.7 reached its end-of-life on January 1, 2020, meaning it no longer receives official support or updates. Despite this, it remains the default in Ubuntu due to the vast amount of legacy Python 2 code still in use.
Ubuntu’s Transition to Python 3
Ubuntu has been actively encouraging developers to transition to Python 3. Significant progress has been made in moving Ubuntu’s own projects from Python 2 to Python 3. Starting from Ubuntu 18.04 (Bionic Beaver) and versions released after that, Python 2 is no longer installed by default. Python 3 has been updated to version 3.6, and this is the last LTS release to include Python 2 in the main repository.
In Ubuntu 19.04 (Disco Dingo), Python 2.7 is still present, but Samba and its dependencies have been updated to be Python 3-only. This means that while Python 2 is still present, it is not used by default for these specific packages.
The Role of PEP 394
The Python Enhancement Proposal (PEP) 394 provides a guideline for operating systems on the usage of the python
command. According to PEP 394, the python
command is designed to always invoke Python 2 to prevent errors when Python 2 code is run on Python 3. This is why, in Ubuntu, the python
command still invokes Python 2.7 by default.
Changing the Default Python Version in Ubuntu
Ubuntu provides two packages in newer releases like 20.04: python-is-python2
and python-is-python3
. The former makes python
invoke python2
, while the latter makes it invoke python3
.
If you have no applications dependent on Python 2, you can install python-is-python3
to make python
invoke python3
. You can do this by running the following command:
sudo apt install python-is-python3
In this command, sudo
is used to run the command with root privileges, apt
is the package handling utility in Ubuntu, install
is the command to install a package, and python-is-python3
is the name of the package to install.
Alternatively, you can edit the shebang of your scripts to #!/usr/bin/python3
to directly use python3
as the interpreter. The shebang (#!
) at the start of a script indicates to the system what interpreter to use to run the script.
Conclusion
While Python 2.7 is still the default Python version in Ubuntu, the transition to Python 3 has been actively encouraged and many projects have already migrated. Ubuntu has made efforts to provide options for using Python 3 as the default version, and developers can choose to install and use Python 3 alongside Python 2.
The ongoing support for Python 2.7 in Ubuntu is a nod to the vast amount of legacy Python 2 code still in use, but the future is clearly moving towards Python 3. As a developer, it is advisable to make the switch to Python 3 if you haven’t already, to take advantage of its improved features and active support.
Python 2.7 is still the default in Ubuntu due to the large amount of legacy Python 2 code that is still in use. Many developers and applications rely on Python 2.7, and transitioning to Python 3 can be a complex and time-consuming process.
Python 2.7 reached its end-of-life on January 1, 2020, because the Python community decided to focus its efforts on Python 3. Python 2.7 is no longer receiving official support or updates, and developers are encouraged to transition to Python 3 for improved features, performance, and security.
Ubuntu has been actively encouraging developers to transition to Python 3. Starting from Ubuntu 18.04 (Bionic Beaver) and versions released after that, Python 2 is no longer installed by default. Ubuntu’s own projects have been migrated to Python 3, and efforts have been made to update dependencies to be Python 3-only.
PEP 394 provides guidelines for operating systems on the usage of the python
command. According to PEP 394, the python
command is designed to always invoke Python 2 to prevent errors when Python 2 code is run on Python 3. This is why, in Ubuntu, the python
command still invokes Python 2.7 by default.
In newer releases of Ubuntu, such as 20.04, you can install the python-is-python3
package to make python
invoke python3
by default. You can do this by running the command sudo apt install python-is-python3
. Alternatively, you can edit the shebang of your scripts to #!/usr/bin/python3
to directly use python3
as the interpreter.
Yes, it is advisable to switch to Python 3 if you haven’t already. Python 2.7 has reached its end-of-life and is no longer receiving official support or updates. Python 3 offers improved features, performance, and security, and is the future of the Python language.