我一直在互联网上查找,要么是没有人遇到这个问题,要么是没有人能解决这个问题。我使用 deadsnake 存储库来使用 Python 3.8,这似乎有效,但是当我尝试获取 pip 时,它开始抱怨没有 distutils.cmd。这是 WSL Ubuntu 22.04。不应该有 *.cmd 之类的东西。
网上每个自称知道的人都告诉我使用 apt install python3-pip。这只会安装 python3.10,尽管文章是关于获取 python3.8 的。我到处寻找如何在 WSL 上执行此操作的方法,他们要么没有告诉我任何不同的东西,要么没有提到 pip。
有谁知道如何解决这个问题?
编辑:这是错误信息。
Traceback (most recent call last):
File "get-pip.py", line 32267, in <module>
main()
File "get-pip.py", line 135, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 111, in bootstrap
monkeypatch_for_cert(tmpdir)
File "get-pip.py", line 92, in monkeypatch_for_cert
from pip._internal.commands.install import InstallCommand
File "<frozen zipimport>", line 259, in load_module
File "/tmp/tmp4nc0p6x0/pip.zip/pip/_internal/commands/__init__.py", line 9, in <module>
File "<frozen zipimport>", line 259, in load_module
File "/tmp/tmp4nc0p6x0/pip.zip/pip/_internal/cli/base_command.py", line 15, in <module>
File "<frozen zipimport>", line 259, in load_module
File "/tmp/tmp4nc0p6x0/pip.zip/pip/_internal/cli/cmdoptions.py", line 24, in <module>
File "<frozen zipimport>", line 259, in load_module
File "/tmp/tmp4nc0p6x0/pip.zip/pip/_internal/cli/parser.py", line 12, in <module>
File "<frozen zipimport>", line 259, in load_module
File "/tmp/tmp4nc0p6x0/pip.zip/pip/_internal/configuration.py", line 26, in <module>
File "<frozen zipimport>", line 259, in load_module
File "/tmp/tmp4nc0p6x0/pip.zip/pip/_internal/utils/logging.py", line 29, in <module>
File "<frozen zipimport>", line 259, in load_module
File "/tmp/tmp4nc0p6x0/pip.zip/pip/_internal/utils/misc.py", line 43, in <module>
File "<frozen zipimport>", line 259, in load_module
File "/tmp/tmp4nc0p6x0/pip.zip/pip/_internal/locations/__init__.py", line 66, in <module>
File "<frozen zipimport>", line 259, in load_module
File "/tmp/tmp4nc0p6x0/pip.zip/pip/_internal/locations/_distutils.py", line 20, in <module>
ModuleNotFoundError: No module named 'distutils.cmd'
答案1
以下是如何解决问题并为 WSL 安装 Python 3.8 的方法:
转到 WSL 并在您的终端上执行sudo apt remove python3.8 python3.8-minimal python3.8-dev python3-pip
sudo apt install build-essential 然后我们安装 python
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.8 python3.8-dev
然后获取你的 python 的 get-pip
wget https://bootstrap.pypa.io/get-pip.py
然后点
sudo python3.8 get-pip.py
如果您遗漏了distutils
以下内容,可以按照以下方法修复:
sudo apt-get install build-essential
sudo apt-get install python3.8-distutils
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
再说一遍:
sudo python3.8 get-pip.py