2

I have recently upgraded my Ubuntu 18.04 system from python3.7 to python3.8. I now want to install a python3.8 package. So, I ran: python3.8 -m pip install xyz, where xyz is the package name (for example, I have tried torch, numpy, and opencv-python for the package name, and all three packages give the same result). However, this gave the following error messages:

File "/usr/lib/python3.8/runpy.py", line 185, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.8/runpy.py", line 144, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.8/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 29, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 23, in <module>
    from pip.locations import (
  File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in <module>
    from distutils import sysconfig
ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.8/distutils/__init__.py)

So, I took a look at the content of /usr/lib/python3.8/distutils. Indeed, there is no module named sysconfig. In fact, there are only two files: __init__.py and version.py. However, when I look at the same for python3.7 in /usr/lib/python3.7/distutils, I can then see the module sysconfig.

I then tried to reinstall dstutils for python3.8, by running: sudo apt-get install python3.8-distutils. However, this gave me the following error message:

E: Unable to locate package python3.8-distutils
E: Couldn't find any package by glob 'python3.8-distutils'
E: Couldn't find any package by regex 'python3.8-distutils'

So now, I am really stuck! I seem to need distutils to install any packages, but my installation of distutils seems to be incomplete. And yet, I cannot seem to install distutils using apt get.

Please can somebody help?

  • 2
    Historically it has been problematic to tinker with the python installations in Ubuntu, this due to the fact that e.g. apt and apt-get might get affected, for starters. – Hannu Dec 07 '20 at 18:23
  • Yes, I haven't been able to solve this, and will probably do an OS reinstall. Next time I will just stick to using a virtual environment! – John Rowlay Dec 08 '20 at 21:30
  • So, it appears the problems persist. "Reinstall" seems to be the easy way out of this. – Hannu Dec 09 '20 at 13:16

1 Answers1

0

An Answer:

The Ubuntu package manager, i.e. apt or apt-get is heavily dependent on a working python; so heavily that it isn't easy to replace or update the python installation.

Also note: As of 20.04, there is no installed python2 in Ubuntu.

Any problems similar to the above; the easy way out is a reinstall.

Hannu
  • 5,374
  • 1
  • 23
  • 40