The other day I decided that I wanted the command python to default to firing up python3 instead of python2.
So I did this:
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 3$ sudo update-alternatives --config python$ sudo update-alternatives --config pythonThere are 2 choices for the alternative python (providing /usr/bin/python). Selection Path Priority Status------------------------------------------------------------* 0 /usr/bin/python3.5 3 auto mode 1 /usr/bin/python2.7 2 manual mode 2 /usr/bin/python3.5 3 manual modePress <enter> to keep the current choice[*], or type selection number: 0
And that all worked. Great! :)
$ python -VPython 3.5.2
But it wasn't long before I realised I had broken apt/aptitude when it comes to installing and removing python packages because apt was expecting python2 it transpired.
This is what happened.
$ sudo apt remove python-sambaReading package lists... DoneBuilding dependency tree Reading state information... DoneThe following package was automatically installed and is no longer required: samba-libsUse 'sudo apt autoremove' to remove it.The following packages will be REMOVED: python-samba0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.After this operation, 5,790 kB disk space will be freed.Do you want to continue? [Y/n] (Reading database ... 187285 files and directories currently installed.)Removing python-samba (2:4.3.11+dfsg-0ubuntu0.16.04.5) ... File "/usr/bin/pyclean", line 63 except (IOError, OSError), e: ^SyntaxError: invalid syntaxdpkg: error processing package python-samba (--remove): subprocess installed pre-removal script returned error exit status 1Traceback (most recent call last): File "/usr/bin/pycompile", line 35, in <module> from debpython.version import SUPPORTED, debsorted, vrepr, \ File "/usr/share/python/debpython/version.py", line 24, in <module> from ConfigParser import SafeConfigParserImportError: No module named 'ConfigParser'dpkg: error while cleaning up: subprocess installed post-installation script returned error exit status 1Errors were encountered while processing: python-sambaE: Sub-process /usr/bin/dpkg returned an error code (1)
Eventually I guessed it wanted python2 as the default, so I undid my changes as follows:
$ sudo update-alternatives --config pythonThere are 2 choices for the alternative python (providing /usr/bin/python). Selection Path Priority Status------------------------------------------------------------* 0 /usr/bin/python3.5 3 auto mode 1 /usr/bin/python2.7 2 manual mode 2 /usr/bin/python3.5 3 manual modePress <enter> to keep the current choice[*], or type selection number: 1$ python -VPython 2.7.12
And then apt worked again
$ sudo apt remove python-sambaReading package lists... DoneBuilding dependency tree Reading state information... DoneThe following package was automatically installed and is no longer required: samba-libsUse 'sudo apt autoremove' to remove it.The following packages will be REMOVED: python-samba0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.1 not fully installed or removed.After this operation, 5,790 kB disk space will be freed.Do you want to continue? [Y/n] (Reading database ... 187285 files and directories currently installed.)Removing python-samba (2:4.3.11+dfsg-0ubuntu0.16.04.5) ...
So I have had to leave it as defaulting to python 2 but I develop in python 3 and so would like my system to default to python 3 for when I run python and idle.
Can anyone tell me how I can achieve this without breaking apt?
My system is a Raspberry Pi 3B running Ubuntu:
Linux mymachine 4.4.38-v7+ #938 SMP Thu Dec 15 15:22:21 GMT 2016 armv7l armv7l armv7l GNU/Linux
(It's actually an arm v8)
$ cat /etc/lsb-release DISTRIB_ID=UbuntuDISTRIB_RELEASE=16.04DISTRIB_CODENAME=xenialDISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"