【问题标题】:Error "ssl module in Python is not available" when using pip in a Python 3.7 virtual environment在 Python 3.7 虚拟环境中使用 pip 时出现错误“Python 中的 ssl 模块不可用”
【发布时间】:2019-01-16 18:11:16
【问题描述】:

在虚拟机中激活的虚拟环境中,我无法使用 pip 安装任何软件包,因为它会引发 SSL 相关错误。

我正在设置一个虚拟环境(使用 virtualenv)来模拟我将要使用的服务器的设置。因此,我在 Ubuntu 18.04 虚拟机(使用 VirtualBox)中手动(从 tar 文件)安装了特定版本的 python(3.7.0)。一旦我选择的 python 版本开始运行,我就激活了一个虚拟环境。点子版本是 18.1。

当我尝试安装 python 包时出现问题,例如:

$ pip install django

它引发了这个错误:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting django
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/django/
Could not fetch URL https://pypi.org/simple/django/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/django/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
Could not find a version that satisfies the requirement django (from versions: )
No matching distribution found for django

搜索后找到的答案都没有帮助我。由于 pip 不能安装任何东西,它不能安装像 ssl 或 OpenSSL 这样的包。如果有人可以帮助我,我提前非常感谢。

【问题讨论】:

  • 你可以使用 Ubuntu 的包管理器来安装 python3.7 而不是使用 tar 文件吗?然后,首先,您可能会默认获得 ssl 模块(它是标准库的一部分)。否则,您可能需要将 ssl 库放入您的 tarball。你是如何制作压缩包的?
  • 如果您从源代码压缩包编译 python,那么您没有链接到 OpenSSL,因此没有 SSL 模块。这种情况下的解决方案是删除 python 并重新编译它,链接到 OpenSSL 库。如果您在其他地方下载了发行版,那么它的作者在没有 OpenSSL 的情况下编译了它,并且发行版无法使用;再找一个。
  • 仍然,为什么不在 Ubuntu vm 中从 apt-get 安装 python3?
  • @hoefling 如何将它与 OpenSSL 链接?我从 python.org 本身下载了发行版。
  • @JawguyChooser 我没有意识到除了从 .tar 文件安装之外,我怎么能通过其他方式安装 Python 3.7.0。我可以指定 'sudo apt-get install python3.7',安装 3.7.1,但 'sudo apt-get install python3.7.0' 不起作用。

标签: python python-3.x pip virtualenv


【解决方案1】:

我无法安装 pandas-datareader。我收到了同样的错误信息。 然后,在 CMD 窗口中,我只需输入命令“activate base”,然后再次运行 pip 即可。 我在“激活基础”之前和之后尝试过使用 django,如果它之前不起作用,那么它确实在之后起作用。 我认为这只是一些没有正确配置的环境变量。 幸运的是,这也对你有用。 祝你今天过得愉快 雷米

【讨论】:

  • 感谢您的帮助!但是,不幸的是,它对我不起作用,因为我使用的是 Linux Ubuntu。 activate base 未被识别为存在的命令。
猜你喜欢
  • 1970-01-01
  • 2021-01-21
  • 1970-01-01
  • 2019-07-01
  • 1970-01-01
  • 2018-07-03
  • 2012-07-24
  • 2022-07-25
  • 1970-01-01
相关资源
最近更新 更多