pip3 在 Ubuntu 18.04 上重新安装

pip3 在 Ubuntu 18.04 上重新安装

最近我在 Ubuntu 18.04 上遇到了一个问题pip3不能正常工作:

:~$ pip3 install jinja2
Traceback (most recent call last):
  File "/home/redra/.local/bin/pip3", line 7, in <module>
    from pip import main
ModuleNotFoundError: No module named 'pip'

然后我尝试重新安装 pip3,似乎是由于它而导致的,并且面临另一个问题:

:~$ sudo -H python3 get-pip.py
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting pip
  Retrying (Retry(total=4, 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/pip/
  Retrying (Retry(total=3, 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/pip/
  Retrying (Retry(total=2, 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/pip/
  Retrying (Retry(total=1, 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/pip/
  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/pip/

我猜是卡住了...由于 pip3 不好,我无法安装 openssl,并且由于 openssl 无法安装新的 pip3 ...似乎是循环(

有什么建议吗?有人遇到过同样的问题吗?

答案1

这可能是因为openssl编译 Python 时所需的二进制文件不存在,为了解决这个问题

  • 从以下地址下载 openssl (tar.gz 即可):https://www.openssl.org/source/

  • 在文件夹中解压 SSL 源文件

  • 进入文件夹并运行以下命令来制作 openssl

    ./configure && make && sudo make install

最后 - 重新进行 Python 编译(configure、make、make install),观察 ssl 库现在是否编译到 Python 中,因为它出现在 Python 编译程序正在寻找的标准位置。

相关内容