【问题标题】:pip3 can't install for Python3.8 due to certificate errors由于证书错误,pip3 无法为 Python3.8 安装
【发布时间】:2021-02-23 22:11:45
【问题描述】:

让我先说一下,这个问题在 Stack Overflow 上出现了很多。我已经阅读了许多这些答案并尝试了许多解决方案,但都没有解决我的问题。但首先,问题来了:

我尝试过的一些事情(并非详尽无遗):

pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package_name>
python3 -m pip install <package_name>
pip3 install <package name>

每次都或多或少相同的错误:

Defaulting to user installation because normal site-packages is not writeable
Could not fetch URL https://pypi.org/simple/venv/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/venv/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement venv (from versions: none)
ERROR: No matching distribution found for venv
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

我在 WSL2 Ubuntu 20.04 上运行它。 我感谢任何想法或建议。我还完全重新安装了 python,尝试了不同版本的 python,重新安装了 pip,尝试了不同版本的 pip,以及其他一些事情。

编辑: type -a python3 python3.8 , python3 , import ssl 的结果

python3 is /usr/local/bin/python3
python3 is /usr/bin/python3
python3 is /bin/python3
python3.8 is /usr/local/bin/python3.8
python3.8 is /usr/bin/python3.8
python3.8 is /bin/python3.8
#@#:/usr/local/lib$ python3
Python 3.8.6 (default, Nov 19 2020, 14:27:22)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/ssl.py", line 98, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'

【问题讨论】:

  • python3 -m ensurepip
  • 您是如何安装/重新安装 Python 的?如果您从源代码构建它,看起来可能会发生这种情况。见this answer
  • @PedroLobito ensurepip 工作并表示满足所有条件。
  • @wjandrea 我现在正在尝试回答这个问题,但在 /usr/local/lib/Python3.8 中找不到 ./configure 文件。那是我应该期待的吗?
  • @wjandrea 我将结果添加到我的原始答案中,因为评论有点多。

标签: python python-3.x linux pip


【解决方案1】:

问题是您在/usr/local/bin 中“本地”安装了python3python3.8,它们显然没有ssl 模块。它们在PATH 中更高,因此它们覆盖了/usr/bin 中的系统安装

所以在此期间,您应该可以像这样使用pip

/usr/bin/python3 -m pip ...

最终,您可能希望删除本地安装。但是,你没有提到你是如何安装它们的,所以我没有更多的细节。可能,您是从源代码构建的,然后是 make altinstall

【讨论】:

  • 你说的很对,谢谢你的帮助!这一周一直困扰着我。
【解决方案2】:

我在安装其他 pip 时遇到此错误。

尝试使用-m pip3 install &lt;package_name&gt;

而不是-m pip install &lt;package_name&gt;

【讨论】:

  • 我试过这个,但得到no module named pip3,即使我安装了pip3。所以我猜也许 pip3 是在错误的地方?目前它在 usr/local/bin
  • @Artemis 是的,pip3 不是模块的名称。 IDK 他们在说什么。
  • 您是否使用 VPN 或专用网络来执行此操作?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-01
  • 2020-12-04
  • 1970-01-01
  • 2020-08-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多