警告:pip配置了需要TLS/SSL的位置,但Python中的ssl模块不可用。

16
我希望您能在Google云计算引擎上使用Python3.8.x。
首先,我使用gcloud命令创建了一个实例。
gcloud compute instances create \
  pegasus-test \
  --zone=asia-northeast1-b \
  --machine-type=n1-highmem-8 \
  --boot-disk-size=500GB \
  --image-project=ml-images \
  --image-family=tf-1-15 \
  --maintenance-policy TERMINATE --restart-on-failure

默认情况下,Python版本为3.5.3。

python3 -V
Python 3.5.3

因此,我升级了Python。我按照这个指示进行操作。(谷歌云计算引擎更改为Python 3.6
cd /tmp
wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz
tar -xvf Python-3.8.3.tgz
cd Python-3.8.3
./configure
sudo apt-get install zlib1g-dev
sudo make
sudo make install

我没有收到任何错误信息。 现在,我有Python3.8.3。

python3 -V
Python 3.8.3

接下来,我想使用 PEGASUS。(https://github.com/google-research/pegasus

git clone https://github.com/google-research/pegasus
cd pegasus
export PYTHONPATH=.
pip3 install -r requirements.txt

然后,我收到了一个错误消息。
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting absl-py (from -r requirements.txt (line 1))
  WARNING: 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/absl-py/
  WARNING: 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/absl-py/
  WARNING: 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/absl-py/
  WARNING: 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/absl-py/
  WARNING: 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/absl-py/
  Could not fetch URL https://pypi.org/simple/absl-py/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(
host='pypi.org', port=443): Max retries exceeded with url: /simple/absl-py/ (Caused by SSLError("Can't connect to HTTPS URL beca
use the SSL module is not available.")) - skipping
  ERROR: Could not find a version that satisfies the requirement absl-py (from -r requirements.txt (line 1)) (from versions: non
e)
ERROR: No matching distribution found for absl-py (from -r requirements.txt (line 1))
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 SS
L module is not available.")) - skipping

我检查了pip的版本。

pip3 -V
pip 19.2.3 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)

所以,我尝试升级pip。 pip3 install --upgrade pip 然后,我收到了以下错误消息。
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Ca
n't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Ca
n't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Ca
n't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Ca
n't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Ca
n't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
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 SS
L module is not available.")) - skipping
Requirement already up-to-date: pip in /usr/local/lib/python3.8/site-packages (19.2.3)
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 SS
L module is not available.")) - skipping

接下来我使用了 pip 而不是 pip3。我输入了 pip install -r requirements.txt

这是结果。

Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: absl-py in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 1)) (0.9.0)
Requirement already satisfied: mock in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 2)) (3.0.5)
Requirement already satisfied: numpy in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 3)) (1.16.6)
Collecting rouge-score
  Downloading rouge_score-0.0.4-py2.py3-none-any.whl (22 kB)
Collecting sacrebleu
  Downloading sacrebleu-1.3.7.tar.gz (26 kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-HCHhuX/sacrebleu/setup.p
y'"'"'; __file__='"'"'/tmp/pip-install-HCHhuX/sacrebleu/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f
.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/
pip-install-HCHhuX/sacrebleu/pip-egg-info
         cwd: /tmp/pip-install-HCHhuX/sacrebleu/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-HCHhuX/sacrebleu/setup.py", line 65, in <module>
        version = get_version(),
      File "/tmp/pip-install-HCHhuX/sacrebleu/setup.py", line 56, in get_version
        with open(os.path.join(os.path.dirname(__file__), 'sacrebleu.py'), encoding='utf-8') as fin:
    TypeError: 'encoding' is an invalid keyword argument for this function
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 20.0.2; however, version 20.1.1 is available.
You should consider upgrading via the '/usr/bin/python -m pip install --upgrade pip' command.

我该如何实现pip3 install -r requirements.txt?你能给我一些建议吗?

1
pip 显然使用了你的 Python2.7 安装,这不是你想要的。另外,你的 Python3 是否识别 ssl 模块?如果你输入 python3 -c 'import ssl' 会发生什么? - ewokx
@VivakP非常感谢您的回答。当我输入python3 -c 'import ssl'时,我得到了Traceback(最近的调用最后):File“<string>”,line 1,在<module>中 File“/usr/local/lib/python3.8/ssl.py”,line 98,在<module>中 import _ssl #如果我们无法导入它,请让错误传播 ModuleNotFoundError:没有名为'_ssl'的模块。您能告诉我该怎么做吗? - Kazuaki Suzuki
2个回答

17

我曾经遇到同样的问题,花了几天时间解决。在尝试了许多不同的解决方案后,这个解决方案成功解决了pip ssl问题。


谢谢你的回答。你的解决方案对我的问题也起作用了! - Kazuaki Suzuki

4

通过安装openssl在Windows 10上解决了这个问题。

使用此链接


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接