python-3.x 没有名为distutils的模块....但安装了distutils?

envsm3lx  于 2022-12-15  发布在  Python
关注(0)|答案(4)|浏览(477)

我想升级我的python版本(在本例中升级到3.10),所以在安装python3.10后,我继续尝试添加一些我使用的模块,例如opencv,它遇到了:

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.

由于distutils似乎已经安装,我不能grok如何进行。

qlfbtfca

qlfbtfca1#

看起来distutils有版本控制,所以

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

似乎可以继续下去。

khbbv19g

khbbv19g2#

这帮我解决了

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

您还可以使用您的python版本替换3.7

wwtsj6pe

wwtsj6pe3#

刚升级到新版本,一切正常

6kkfgxo0

6kkfgxo04#

sudo apt-get install python3.9-distutils

这解决了我的问题,我正在使用python3. 9

相关问题