我想升级我的 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 似乎已经安装,我不知道如何继续。
The issue you’re encountering is due to the fact that Python 3.10 is installed, but the required distutils module is missing for this specific version of Python. While the python3-distutils package is already installed, it seems to be for Python 3.8 (as seen in the message), not for Python 3.10.
distutils
python3-distutils
Here’s how you can resolve the issue:
python3.10-distutils
Since you installed Python 3.10 separately, you likely need to install the distutils package for Python 3.10 specifically. You can do this by running:
sudo apt-get install python3.10-distutils
This will install the necessary distutils package for Python 3.10, allowing pip to function correctly with that version.
pip
After installing distutils, ensure that pip is properly installed for Python 3.10:
python3.10 -m ensurepip --upgrade
This will either install pip if it’s missing or upgrade it if necessary.
Once distutils and pip are set up for Python 3.10, you can proceed to install OpenCV:
python3.10 -m pip install opencv-python
It’s always a good idea to make sure pip is up to date:
python3.10 -m pip install --upgrade pip
These steps should resolve the error and allow you to install OpenCV and other packages using Python 3.10.