17

I was wanting to upgrade my python version (to 3.10 in this case) so after installing python3.10 I proceeded to try adding some modules I use e.g. opencv , which ran into:

jeremy@jeremy-Blade:~$ python3.10 -m pip install opencv-python 
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3/dist-packages/pip/__main__.py", line 16, in <module>
    from pip._internal.cli.main import main as _main  # isort:skip # noqa
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 10, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
    from pip._internal.cli import cmdoptions
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 19, in <module>
    from distutils.util import strtobool
ModuleNotFoundError: No module named 'distutils.util'

jeremy@jeremy-Blade:~$ sudo apt-get install python3-distutils
[sudo] password for jeremy: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-distutils is already the newest version (3.8.10-0ubuntu1~20.04).
...
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.

Since distutils already seems to be installed , I can't grok how to proceed.

Talha Tayyab
  • 8,111
  • 25
  • 27
  • 44
jeremy_rutman
  • 3,552
  • 4
  • 28
  • 47

6 Answers6

39

It looks like distutils has versioning , so after

jeremy@jeremy-Blade:~$ sudo apt-get install python3.10-distutils 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
...
Setting up python3.10-lib2to3 (3.10.0-1+focal1) ...
Setting up python3.10-distutils (3.10.0-1+focal1) ...

jeremy@jeremy-Blade:~$ python3.10 -m pip install opencv-python 

seems to be able to proceed.

jeremy_rutman
  • 3,552
  • 4
  • 28
  • 47
10

This solved it for me

sudo apt-get install --reinstall python3.7-distutils

You can also replace 3.7 with your version of python

Ahmed Tremo
  • 137
  • 1
  • 3
4
sudo apt-get install python3.9-distutils

This solved my problem i am using Python3.9

2

distutils package is removed in python version 3.12

It was deprecated in Python 3.10 by PEP 632 “Deprecate distutils module”. For projects still using distutils and cannot be updated to something else, the setuptools project can be installed: it still provides distutils.

https://docs.python.org/3.12/whatsnew/3.12.html

Talha Tayyab
  • 8,111
  • 25
  • 27
  • 44
0

This solved my problem

sudo apt-get install python3.10-distutils

I am using python 3.10

Munsif Ali
  • 1,839
  • 1
  • 8
  • 22
0

Install distutils for your-python-version

!sudo apt-get install python<your-python-version>-distutils

For example, to install in 3.8 version

sudo apt-get install python3.8-distutils

Specification: In Python 3.10 and 3.11, distutils will be formally marked as deprecated. All known issues will be closed at this time.

Note: You could still use distutisl with warning in 3.10 and 3.11 and any issues that arises will not be fixed. But, Code that imports distutils will no longer work from Python 3.12.

For more info: Migragtion Advice