How to make Ubuntu 18.04 LTS use python 3.7 as default?

Sorin Srbu sorin.srbu at ki.se
Thu Jul 30 11:52:40 UTC 2020


On Thu, 2020-07-30 at 11:54 +0200, Bo Berglund wrote:
> On Thu, 30 Jul 2020 06:46:23 +0000, Sorin Srbu <sorin.srbu at ki.se>
> wrote:
> 
> > On Thu, 2020-07-30 at 08:15 +0200, Bo Berglund wrote:
> > > It has python 2.7 installed as its default python and now I am getting
> > > problems because apparently 2.7 is no longer the version used for some
> > > of my tools, which prints messages that all upgrades must use python 3
> > > (actually 3.5 or higher).
> > > I have managed to install 3.7 even though the ubuntu apt system only
> > > provides a much lower version.
> > > I did that using this instruction page:
> > > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flinuxize.com%2Fpost%2Fhow-to-install-python-3-7-on-ubuntu-18-04%2F&data=02%7C01%7Csorin.srbu%40ki.se%7C1aac4aa6bf024545855108d8346ec2d2%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637316997606712358&sdata=URf%2FHPu5z%2B5VrnG4F4ij%2BR301vgjr3wBga0L%2BQH%2BZC0%3D&reserved=0
> > > 
> > > So now I have this:
> > > ~$ python --version
> > > Python 2.7.17
> > > ~$ python2 --version
> > > Python 2.7.17
> > > ~$ python3 --version
> > > Python 3.6.9
> > > ~$ python3.7 --version
> > > Python 3.7.8
> > > 
> > > As you can see I seem to have 3 installed versions but the default
> > > version is the oldest...
> > > 
> > > So how can I make python use version 3 (or even 3.7.8)?
> > > 
> > 
> > Hello Bo!
> > 
> > Maybe try "sudo update-alternatives --config python"?
> > 
> > See eg 
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flinuxconfig.org%2Fhow-to-change-from-default-to-alternative-python-version-on-debian-linux%23h2-change-python-version-system-wide&data=02%7C01%7Csorin.srbu%40ki.se%7C1aac4aa6bf024545855108d8346ec2d2%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637316997606722345&sdata=BCb7E11UzhyHUTgf%2Fmw93btJLegkgDg31SNQxOUUJE4%3D&reserved=0
> > for a nice howto and guide.
> > 
> 
> Thanks for the input! Much appreciated.
> 
> I have done this for all of my installed pythons so now the available
> pythons are:
> 
> update-alternatives --list python
> /usr/bin/python2.7
> /usr/bin/python3.5
> /usr/bin/python3.6
> /usr/bin/python3.7
> 
> But when I look in /usr/bin I see a problem (edited list to remove
> leading fluff):
> 
> ls -la /usr/bin/python*
> /usr/bin/python -> /etc/alternatives/python
> /usr/bin/python2 -> python2.7
> /usr/bin/python2.7
> /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
> /usr/bin/python2-config -> python2.7-config
> /usr/bin/python3 -> python3.6
> /usr/bin/python3.5
> /usr/bin/python3.5m
> /usr/bin/python3.6
> /usr/bin/python3.6m
> /usr/bin/python3.7
> /usr/bin/python3.7m
> /usr/bin/python3-futurize
> /usr/bin/python3m -> python3.6m
> /usr/bin/python3-pasteurize
> /usr/bin/python3-pbr
> /usr/bin/python3-wsdump
> /usr/bin/python-config -> python2.7-config
> 
> Note the last line concerning the config!!!!
> It still points to python2.7
> 
> Is this really correct or is the config either portable or not used?

Hello Bo!

You really should consider rewriting (as neccessary) your python2-scripts to
python3. Python2 reached its end-of-life in january 2020 IIRC, and no more
security patches will be released.

With that said, Canonical may still yet provide backports for it (at their
discretion I guess), judging from earlier package histories.
See eg 
https://askubuntu.com/questions/1065593/will-it-be-safe-to-use-python-2-7-on-ubuntu-18-04-after-python-2-eol
 for some in sights.


I ran the ls -la /usr/bin/python* command above on my Kubuntu 20.04 and see
no config-files that you have. 
In any case, the 

/usr/bin/python-config -> python2.7-config 

is a symbolic link pointing to 

/usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config

Those are probably remains from previous upgrades.
For curiosity's sake though, what's in x86_64-linux-gnu-python2.7-config?


I don't have any upgraded 18.04 installs I can check.
However, deprecation warnings should be able to be silenced if that works
for you. I'm a bit on thin ice here though.
Maybe others can chime in? :-)

What kind of warnings do you get?
Have you tried googling them and see what you can do to fix them?


A side track - My infrastructure colleagues and I have been pestering the
devs at work to check and rewrite old their python2-scripts, in order to be
"future-safe".
It's a long process though, and you might want to look into this kinda'
nowish IMHO.


-- 

Sorin Srbu, Serverdrift
Karolinska Institutet Universitetsbibliotek
Avdelningen för Verksamhetsstöd
Enheten för Teknikstöd och Bildproduktion
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20200730/ecefe8c1/attachment.sig>


More information about the ubuntu-users mailing list