109

Having used Ubuntu 18.04 for a handful of years now, and reading that Python 2 has been removed from Ubuntu 20.04, I was looking forward to using the commands python or pip rather than python3 or pip3. So today I tried Ubuntu 20.04 for the first time, and found:

$ python --version

Command 'python' not found

$ python3 --version
Python 3.8.5

I was surprised and upon looking into things further found the following about the package python-is-python3:

https://packages.ubuntu.com/focal/python-is-python3

https://launchpad.net/ubuntu/focal/+package/python-is-python3

How to make 'python' program command execute Python 3?

The middle of these 3 links is the most descriptive, but none are especially clear about what python-is-python3 is/does and the full scope of ramifications if sudo apt-get install python-is-python3 was to be ran on a Ubuntu 20.04 install.

Here are some questions I have about python-is-python3:

  1. Is python-is-python3 proprietary to Ubuntu/Canonical? If so, do other Linux distributions use python-is-python3 also or do some other distributions have a similar equivalent?

  2. I gather if I was to run python-is-python3 from the command prompt then I could use the command python instead of python3. First can somebody confirm this, and second, does the same go for pip, i.e. pip instead of pip3?

  3. The launchpad.net link above mentions creation of a symlink. Does python-is-python3 really just create a single symlink? It seems odd to introduce a package for such a bare bones purpose. Also, if this package is subsequently uninstalled (i.e. sudo apt --purge remove python-is-python3) does this remove the symlink?

  4. Are there any commonly used Python 2 packages out there anymore? I can't think of any offhand.

  5. Has anybody ran python-is-python3 and then later regretted doing so due to a reason that was not realized ahead of time?

  6. It seems the benefit of running python-is-python3 would be not having to add the 3 at the end of Python commands, but the disadvantage is that you would then have a non-standard Ubuntu setup, is this a fair summary of the python-is-python3 benefit/drawback?

2
  • 5
    1) No. 2) Yes. No. 3) Yes. Yes. 4) No. 5) Impossible to know with certainty, since we don't allow rants or reviews here. 6) Yes.
    – user535733
    Dec 2, 2020 at 2:22
  • "do some other distributions have a similar equivalent?" - RHEL8 did something similar, and broke everything that had a shebang of #!/usr/bin/env python. Manjaro, which I use these days, seemed to handle the switch from Python 2 to 3 more smoothly.
    – Aaron F
    Dec 2, 2020 at 12:35

2 Answers 2

80

As the package description you linked to says:

In Ubuntu, all python packages use explicit python3 or python2 interpreter and do not use unversioned /usr/bin/python at all ... No packages may declare dependencies on this package.

So, all official Ubuntu packages will depend explicitly on "python2" or "python3", and invoke the appropriate command. The default "python" command is deliberately undefined so that any scripts referencing it have to be updated to unambiguously depend on one version or the other.

However, users may have code that relies on the "python" command being available, and know that they can safely point it across their whole system to one version or the other. The python-is-python3 package (and its counterpart, python-is-python2) are a convenient way to set up a symlink for this purpose.

Does python-is-python3 really just create a single symlink? It seems odd to introduce a package for such a bare bones purpose.

Linux distributions are extremely complex systems made up of a large number of simple components. The power of package managers comes in their flexibility to do simple things like this in a unified way. For instance, 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. Shipping a package for this purpose is considerably simpler than having a user guide explaining how to manage the symlink manually.

Does the same go for pip, i.e. pip instead of pip3?

Apparently not - according to this LaunchPad bug, the python3 package automatically points pip at pip3 anyway.

If you open up the .deb file for the package (I used 7-Zip), you can see that apart from some documentation, it really does just contain one symlink, to be installed at /usr/bin/python, pointing to /usr/bin/python3.

1
  • 8
    As for pip - to avoid surprises (think: many Python versions in the system, plus conda envs, plus virtualenvs...), it is often a good idea to run it as [/path/to/]python -m pip ... Dec 2, 2020 at 22:16
25

In Ubuntu, all python packages use explicit python3 or python2 interpreter and do not use unversioned /usr/bin/python at all. Some third-party code is now predominantly python3 based, yet may use /usr/bin/python.

python-is-python3 is a convenience package which ships a symlink to point the /usr/bin/python interpreter at the current default python3. It may improve compatibility with other modern systems, while breaking some obsolete or third-party software.

python-is-python3 replaces: python, python-is-python2.

I installed python-is-python3 as a convenience package in Ubuntu 20.04, but I later uninstalled it after python2.7 was automatically installed as a dependency of another package.

3
  • 1
    See my askubuntu.com/questions/1295530/…, and it'll explain why python-is-python2 got installed.
    – heynnema
    Dec 8, 2020 at 17:26
  • I think the url of your references is needed.
    – Good Pen
    Jun 12, 2023 at 8:28
  • The reference I used is the output of apt show python-is-python3
    – karel
    Jun 12, 2023 at 11:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .