Python is a popular high-level programming language. It’s now being used to build a large part of the internet, randing from large-scale web applications to major part of various operating system. Ubuntu/Debian includes Python as part of their standard packages. But the languages has evolved in such a way that Python 3 does not backward compatible with its Python 2.x sibling, which leads to confusion among Linux beginners. python-is-python3 is a Ubuntu package which aims to be a part of the solution. In this article, we will try to explain the state of Python in Ubuntu and how python-is-python3 packages plays a role in that.
python-is-python3 on Ubuntu
On Ubuntu version 18.10 and older, both Python 2 and Python 3 was shipped with the OS. Python 2 can be called by running
python in a terminal, while
python3 is the alias for Python 3.
On Ubuntu 20.04 onwards, the developers removed and modified the legacy source code so that Python 2 can be removed. Only Python 3 is shipped with the OS out of the box. Because of that,
python command now points to Python 3.
Newer versions of popular software acknowledge this change and update their code accordingly, so that the programs does not accidentally run Python 3 code in Python 2.x, which leads to errors. But a lot of them still expect
python to be Python 2.x, renders the program unusable on Ubuntu 20.04 and later.
That’s where python-is-python3 package comes into play. The package simply points
python command (and binary path) to Python 3.
python-is-python3 really just create a single symlink? You may wonder why introducing a separate package for such a bare bone purpose. The answer is simplicity. Linux distributions are extremely complex systems consist of many simple components that does their own things. The power of package managers comes in their flexibility to do simple things like this in a unified way. For example, a server setup script might have a long list of
apt packages that an application needs to be installed, and can simply include
python-is-python3 in that list. Having a dedicated package to make a symlink or a set of symlinks is considerably simpler than having a guide explaining how to create and manage the symlink manually.
And if you like the idea of having a dedicated package for making symlinks, there is a package similar to
How to use python-is-python3
python-is-python3 provides neither a command-line interface nor GUI, all you need to do is install it onto your system by running the following command:
sudo apt-get install python-is-python3 -y
Once the installation is done,
python command will use Python 3.x binary.
python-is-python3 on macOS
First and foremost,
python-is-python3 is an Ubuntu-only package, which means there is no
python-is-python3 for macOS. But if you’re looking for the proper way to install or set Python 3 as default on Mac, we’ve got a few solutions.
Install Python 3 from installer
There’s a Python 3 installer for macOS that can be downloaded from Python official website. This installer places a new binary named python3 in /usr/local/bin/. If we want
python command to call Python 3 instead of Python 2 on macOS, alias the command to the proper binary by running the following command.
echo "alias python=/usr/local/bin/python3.8" >> ~/.zshrc
If you are using the default Bash shell, you can append this same line to your .bashrc:
echo "alias python=/usr/local/bin/python3.8" >> ~/.bashrc
Please note that you won’t be able to automatically update Python if you’re doing things this way.
Install Python 3 with Homebrew
Homebrew is the macOS alternative for
yum package manager. We’re going to use pyenv – a separate package used to manage multiple Python versions on the same machine. If you’ve got Homebrew installed on your system, run the following command to install pyenv.
brew install pyenv
Then, install Python 3.8.6 by running:
pyenv install 3.8.6
You can replace 3.8.6 with whatever version you want to install.
Alternatively, you can directly install Python with
brew by running
brew install python, but it’s not recommended since there are significant API changes in different Python 3.x releases, which may lead to error messages in your programs.
Once we’ve got Python3 installed, repeat the configuration steps above with
Fix python-is-python3 command not found
As I mentioned earlier,
python-is-python3 provides neither a command-line interface nor a graphical user interface.
If you’re trying to call it by running
python-is-python3 in a terminal, you’d be greeted with the
python-is-python3 command not found error. There’s simply nothing you can do about that.
We hope that the information above is useful to you. You may be interested in our guide on fixing “pip: command not found” error, “[Errno 32] Broken pipe” in Python and fix “Shadows name from outer scope” in PyCharm.
If you have any suggestions, feel free to comment below and we will add them to the article.