【问题标题】:With python installed from source can't install any package with pip (SSL module is not available)使用从源代码安装的 python 无法使用 pip 安装任何包(SSL 模块不可用)
【发布时间】:2022-12-21 05:56:02
【问题描述】:

我在 Ubuntu 22.04.1 上,它带有自己的 python3.11,pip 可以完美运行。 如果我通过 apt-get (sudo apt-get install python3.10) 安装其他 python 版本,则相关的 pip 可以完美运行。

但是我刚刚从源代码安装了一个替代的 python 版本(3.7.9)(我不能为这个 python 版本使用 apt),执行以下操作

cd usr/lib
sudo wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
sudo tar xzf Python-3.7.9.tg
cd Python-3.7.9
sudo ./configure --enable-optimizations
sudo make altinstall

Python3.7 工作正常,但是如果我尝试安装任何包(使用 pip3.7,或者在创建基于 python3.7 的 virtualenv 之后,使用 pip),我会收到以下警告

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

其次是错误

ERROR: Could not find a version that satisfies the requirement numpy (from versions: none)
ERROR: No matching distribution found for numpy 

我确定我已经安装了 Openssl,因为其他版本的 python 不会用 pip 给出问题(我也可以在文件夹/etc/ssl 中看到 ssl)所以问题似乎只与 ssl 和 python 之间的链接有关从源安装.

有什么建议么?

【问题讨论】:

  • 提示 1:当您真的不需要时,请避免使用 sudo。下载编译不需要sudomake install才需要。
  • 提示 2:观察 ./configure 的输出。是的,它很大而且很无聊。但这堆中隐藏着宝石。特别注意缺少库的问题。
  • 提示 3:要编译 Python 的 _ssl.so 模块,您需要 OpenSSL 开发文件(头文件和链接库)。我不是 100% 确定,但我认为你需要 sudo apt install openssl-devel。清理之后,重新配置并重新编译 Python。像这样:sudo chown -R $USER . && make distclean && ./configure && make && sudo make altinstall
  • 对不起,是sudo apt install libssl-dev
  • 谢谢,但在我的情况下 openssl 已经安装但是从源代码编译的 python 无法“看到”它(从 apt-get 安装的 python 没有这个问题),我想我找到了解决我的特定问题的方法,我贴在下面

标签: python-3.x ubuntu ssl pip openssl


【解决方案1】:

如果它可以帮助任何人,我找到了解决方案: 在做之前

sudo ./configure --enable-optimizations
sudo make altinstall

我只是修改了文件 Modules/Setup.dist 的一部分

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
# _ssl _ssl.c 
#    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl 
#    -L$(SSL)/lib -lssl -lcrypto

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/etc/ssl
_ssl _ssl.c 
    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl 
    -L$(SSL)/lib -lssl -lcrypto

请注意,/etc/ssl 是我安装 ssl 的实际位置。

文件修改后我比安装

sudo ./configure --enable-optimizations
sudo make altinstall

现在(在最终升级 pip 和 setuptools 之后)pip 工作正常。

【讨论】:

    【解决方案2】:

    对于 Ubuntu 22.04.1 上的 Python 3.11.1,不需要修改任何分发文件,只需在 ./configure 命令行中添加 --with-openssl-rpath=/usr/lib/x86_64-linux-gnu 即可。

    ssl 和加密库在该目录中,这确保它们在运行时位于

    请注意,这假设您在 x86_64 发行版上运行,我希望 ARM 上有一个类似的目录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-29
      • 1970-01-01
      • 1970-01-01
      • 2021-07-04
      • 1970-01-01
      • 2015-08-19
      • 2012-01-24
      • 1970-01-01
      相关资源
      最近更新 更多