我已经使用apt在Xubuntu 20.04上安装了python 3.9。当我尝试运行pip时,我得到了错误No module named 'distutils.cmd'
例如,python3.9 -m pip --help
给出了回溯
File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/saul/.local/lib/python3.9/site-packages/pip/__main__.py", line 29, in <module>
from pip._internal.cli.main import main as _main
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/main.py", line 9, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/autocompletion.py", line 10, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
from pip._internal.cli import cmdoptions
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/cmdoptions.py", line 23, in <module>
from pip._internal.cli.parser import ConfigOptionParser
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/parser.py", line 12, in <module>
from pip._internal.configuration import Configuration, ConfigurationError
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/configuration.py", line 26, in <module>
from pip._internal.utils.logging import getLogger
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/utils/logging.py", line 27, in <module>
from pip._internal.utils.misc import ensure_dir
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/utils/misc.py", line 39, in <module>
from pip._internal.locations import get_major_minor_version
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/locations/__init__.py", line 14, in <module>
from . import _distutils, _sysconfig
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/locations/_distutils.py", line 9, in <module>
from distutils.cmd import Command as DistutilsCommand
ModuleNotFoundError: No module named 'distutils.cmd'
我在哪里可以找到distutils.cmd
?我应该把它放在哪里?我对linux一点也不了解,只是一个天真的用户。
我发现这篇文章表明python3.9没有单独的distutils模块,并且似乎建议使用虚拟环境。当我尝试时
python3.9 -m venv /home/saul/.venvs/py39
然而,我收到了的消息
Error: Command '['/home/saul/.venvs/py39/bin/python3.9', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.9 get-pip.py
(可能会出错,我试过了,它给了我一个错误(
sudo apt install python3.9-distutils
python3.9 get-pip.py
(可以跳过并直接检查版本,如果它有效,那么很好,否则运行此命令,然后检查版本。我在检查版本之前运行了此命令(
最后,
python3.9 -m pip -V
(应将控制台作为pip 22.x.x from some-path (python3.9)
(
我执行了这些命令,它对我有效。希望它也能帮助你。
我偶然发现了这个,它起了作用:
sudo apt install python3.9-venv