2021-05-09
md
python-is-python Pain
<-Scanning with the Brother DCP-7040 Multifunction Printer in Mint 20.1 or Ubuntu 20.04
 ToirtoiseHG and Virtual Box 6.1 in Mint 20.1 

Here is another post that is definitely not intended for a general audience. It discusses the conflict between the python-is-python3 and python-is-python2 packages when installing TortoiseHg and Oracle Virtual Box on Mint 20.1. Without doubt the source of the problem is the simultaneous presence of versions 2.7 and 3.8 of the Python interpreter and the ambiguity of the python command.

michel@hp:~$ ls -l /usr/bin/python* lrwxrwxrwx 1 root root 9 mar 13 2020 /usr/bin/python2 -> python2.7 -rwxr-xr-x 1 root root 3674216 mar 8 09:02 /usr/bin/python2.7 lrwxrwxrwx 1 root root 9 mar 31 16:22 /usr/bin/python3 -> python3.8 -rwxr-xr-x 1 root root 5486384 jan 27 11:41 /usr/bin/python3.8 ...

The python-is-python2 package adds a symbolic link named python to python2 which ultimately is translated to python2.7. Likewise, the python-is-python3 packages adds a symbolic link also named python to python3 and hence to python3.8. Clearly, these two packages are mutually exclusive.

According to the dpkg journal, the installation of Virtual Box version 6.1.18 on April 3 was immediately preceded by the installation of python-is-python2.

2021-04-03 09:32:23 install libgcc1:amd64 <none> 1:10.2.0-5ubuntu1~20.04 2021-04-03 09:32:23 install libqt5opengl5:amd64 <none> 5.12.8+dfsg-0ubuntu1 2021-04-03 09:32:23 install libsdl1.2debian:amd64 <none> 1.2.15+dfsg2-5 2021-04-03 09:32:23 install python-is-python2:all <none> 2.7.17-4 2021-04-03 09:32:23 install virtualbox-6.1:amd64 <none> 6.1.18-142142~Ubuntu~eoan

It is surprising that software developed by a large company and updated so often still uses Python 2 when in November 2008 the Python foundation announced the end of the 2.x versions of Python and, indeed, its latest patch (2.7.18) goes back to April 4, 2020 (PEP 3.03).

A few days later, when TortoiseHG (thg) was installed on Mint Mate 20.1 according to the instructions on ask ubuntu/Stack Exhange, both Virtual Box and python-is-python2 were eliminated from the system.

michel@hp:~/thg$ sudo apt-get install python-is-python3 Lecture des listes de paquets... Fait ... Les paquets suivants seront ENLEVÉS : python-is-python2 virtualbox-6.1 Les NOUVEAUX paquets suivants seront installés : python-is-python3 0 mis à jour, 1 nouvellement installés, 2 à enlever et 2 non mis à jour. ...

The python-is-python3 package was not a prerequisite of thg, but simply an individual's suggestion to ensure that the script was compiled with Python version 3. I verified that the integration of TortoiseHG in Caja worked after removing the symbolic link /usr/bin/python to /usr/bin/python3 created by the python-is-python3 package. However, I could no longer launch TortoiseHG Workbench from the MATE menu and a bash script that launched Workbench no longer worked. I correctly estimated that it would be easy to fix these problems so I proceeded to remove python-is-python3 and reinstall Virtual Box. Although a new version (i.e. 6.1.22) was available, the python-is-python2 package remained a prerequisite.

michel@hp:~$ grep "install " /var/log/dpkg.log ... 2021-05-08 18:29:22 install python-is-python2:all <none> 2.7.17-4 2021-05-08 18:29:23 install virtualbox-6.1:amd64 6.1.18-142142~Ubuntu~eoan 6.1.22-144080~Ubuntu~eoan michel@hp:~$ ls -l /usr/bin/python lrwxrwxrwx 1 root root 5 mai 15 2020 /usr/bin/python -> python2

I did not want the python to python2 link, since it is preferable to get rid of this obsolete version of Python. Unfortunately, we cannot simply eliminate the python-is-python2, as this will result in the elimination of Virtual Box. Fortunately, the latter seems to work fine after removing the symbolic link python -> python2.

michel@hp:~$ sudo rm /usr/bin/python michel@hp:~$ ls -l /usr/bin/python* lrwxrwxrwx 1 root root 9 mar 13 2020 /usr/bin/python2 -> python2.7 -rwxr-xr-x 1 root root 3674216 mar 8 09:02 /usr/bin/python2.7 lrwxrwxrwx 1 root root 9 mar 31 16:22 /usr/bin/python3 -> python3.8 -rwxr-xr-x 1 root root 5486384 jan 27 11:41 /usr/bin/python3.8

If all of this were to be started over, I would do the following to have TortoiseHG and Virtual Box on a Mint 20.1 system.

  1. Download the latest version of Virtual Box for Ubuntu 19.10/20.04/20.10/21.04.
  2. Install Virtual Box. The easiest way is to right-click on the name of the downloaded file in a file browser, the choose Opent With GDebi Package Installer option in the context menu and then proceed with the installation.
  3. Eliminate the symbolic link python to python2 if it exists :
    michel@hp:~$ ls -l /usr/bin/python lrwxrwxrwx 1 root root 16 mai 10 00:57 /usr/bin/python -> /usr/bin/python2 michel@hp:~$ sudo rm /usr/bin/python
  4. Create the python to python3 symbolic link:
    michel@hp:~$ sudo ln -s /usr/bin/python3 /usr/bin/python
  5. Install ToroiseHG according to the instructions in the ask ubuntu forum, except that the python-is-python3 package as indicated in step 5 must not be installed. The symbolic link created in the previous step is sufficient.
  6. After all that, it would be preferable to eliminate the python to python3 link in /usr/bin
    michel@hp:~$ sudo rm /usr/bin/python

I explained above why there should not be a python to python2 link, but according to the descriptions of the python-is-python2 and python-is-python3 packages, the file /usr/bin/python should no longer be present (Starting with the Debian 11 (bullseye) and Ubuntu 20.04 LTS (focal) releases, all python packages use explicit python3 or python2 interpreter and do not use unversioned /usr/bin/python at all) hence this last step. By the way, these descriptions end with another important sentence No packages may declare dependencies on this package, or recommend that package. Clearly, Virtual Box violates this directive.

Finally, the file /home/michel/.local/share/applications/toirtoisehg.desktopt adds TortoiseHG to the Mint 20.1 Mate menu.

[Desktop Entry] Name=TortoiseHg Exec=/usr/bin/python3 /home/michel/thg/thg --nofork Comment=GUI application for using Mercurial Comment[fr]=Interface graphique pour Mercurial Terminal=false Type=Application Icon=/home/michel/thg/icons/svg/thg_logo.svg Categories=Utility;System; Keywords=VCS;SCM;Version control;

As can be seen, the version of Python to use is specified explicitly in the Exec= line as per the directive. Note that it may be necessary to adjust the path to the TortoiseHG script (in other words to thg) depending on the directory in which it was built. I also created a bash script to run TortoiseHG from a command line in a terminal.

#!/bin/bash if [[ "$#" -eq 0 ]]; then adir=$PWD elif [[ "$#" -eq 1 ]]; then adir=$1 else echo "syntaxe: thg [répertoire]" exit 2 fi /usr/bin/python3 /home/michel/thg/thg --nofork -R $adir

As before, the version of the Python interpreter used is specified explicitly.

<-Scanning with the Brother DCP-7040 Multifunction Printer in Mint 20.1 or Ubuntu 20.04