Pip:连接因“ProtocolError”而中断

Ste*_*fan 4 python pip python-3.x

我正在尝试在Ubuntu 20.04.5pip上的全新虚拟环境中安装软件包,但当我第二次运行时,我不断收到以下警告。第一次尝试后软件包安装失败。pip

\n
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pip/\nWARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pip/\nWARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pip/\nWARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pip/\nWARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pip/\nWARNING: There was an error checking the latest version of pip.\n\n
Run Code Online (Sandbox Code Playgroud)\n

在新鲜环境中的第一次尝试有效

\n
./venv/bin/pip install --upgrade pip\nCollecting pip\n  Using cached pip-22.2.2-py3-none-any.whl (2.0 MB)\nInstalling collected packages: pip\n  Attempting uninstall: pip\n    Found existing installation: pip 20.0.2\n    Uninstalling pip-20.0.2:\n      Successfully uninstalled pip-20.0.2\nSuccessfully installed pip-22.2.2\n
Run Code Online (Sandbox Code Playgroud)\n

但同一命令随后失败,并且我看到警告消息。

\n
./venv/bin/pip install --upgrade pip\nRequirement already satisfied: pip in ./venv/lib/python3.8/site-packages (22.2.2)\nWARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pip/\nWARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pip/\nWARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pip/\nWARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pip/\nWARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pip/\nWARNING: There was an error checking the latest version of pip.\n
Run Code Online (Sandbox Code Playgroud)\n

我也无法安装其他软件包

\n
./venv/bin/pip install --upgrade numpy\nWARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/numpy/\nWARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/numpy/\nWARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/numpy/\nWARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/numpy/\nWARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/numpy/\nERROR: Could not find a version that satisfies the requirement numpy (from versions: none)\nERROR: No matching distribution found for numpy\nWARNING: There was an error checking the latest version of pip.\n
Run Code Online (Sandbox Code Playgroud)\n

重现步骤

\n

创建新环境:

\n
python3 -m venv venv\nsource ./venv/bin/activate\n
Run Code Online (Sandbox Code Playgroud)\n

检查我使用的 Python 版本

\n
./venv/bin/python --version\nPython 3.8.10\n\n
Run Code Online (Sandbox Code Playgroud)\n

和点

\n
\xe2\x9d\xaf ./venv/bin/pip --version\npip 20.0.2 from /home/$USER/projects/venv/lib/python3.8/site-packages/pip (python 3.8)\n
Run Code Online (Sandbox Code Playgroud)\n

没有使用代理并且我的防火墙已禁用

\n
\xe2\x9d\xaf echo "$http_proxy"\n\n\xe2\x9d\xaf echo "$https_proxy"\n\n\xe2\x9d\xaf sudo ufw status\nStatus: inactive\n\n
Run Code Online (Sandbox Code Playgroud)\n

我可以在同一台计算机上的 Docker 容器中运行相同的步骤,不会出现任何问题。\nMyopenssl.conf没有更改。\n这似乎与我的本地 Python 设置有关。\nMypip config list为空。\n没有配置文件

\n
pip config list -v\nFor variant \'global\', will try loading \'/etc/xdg/pip/pip.conf\'\nFor variant \'global\', will try loading \'/etc/pip.conf\'\nFor variant \'user\', will try loading \'/home/$USER/.pip/pip.conf\'\nFor variant \'user\', will try loading \'/home/$USER/.config/pip/pip.conf\'\nFor variant \'site\', will try loading \'/home/$USER/git/infrastructure-manual-tasks/cropster-csar/resize-login-images/venv/pip.conf\'\n
Run Code Online (Sandbox Code Playgroud)\n

我使用谷歌DNS

\n
Link 12 (ens4)\n      Current Scopes: DNS    \nDefaultRoute setting: yes    \n       LLMNR setting: yes    \nMulticastDNS setting: no     \n  DNSOverTLS setting: no     \n      DNSSEC setting: no     \n    DNSSEC supported: no     \n  Current DNS Server: 8.8.8.8\n         DNS Servers: 8.8.8.8\n                      8.8.4.4\n                      1.1.1.1\n          DNS Domain: ~.     \n
Run Code Online (Sandbox Code Playgroud)\n

我注意到,当我强制pip使用不强制执行的不同镜像时,我可以安装软件包HTTPS。所以这个问题似乎与相关SSL,但我找不到它的来源。

\n

这有效

\n
./venv/bin/pip install --upgrade -i http://pypi.douban.com/simple --trusted-host pypi.douban.com numpy\nLooking in indexes: http://pypi.douban.com/simple\nCollecting numpy\n  Downloading http://pypi.doubanio.com/packages/d6/e2/bed33bdbf513cd6d3fcb4377792ef1b8aad941da542a191e1e2a98c6621f/numpy-1.23.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.1 MB)\n     \xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81 17.1/17.1 MB 6.4 MB/s eta 0:00:00\nInstalling collected packages: numpy\nSuccessfully installed numpy-1.23.3\n
Run Code Online (Sandbox Code Playgroud)\n

但这在使用时不会HTTPS

\n
./venv/bin/pip install --upgrade -i https://pypi.douban.com/simple --trusted-host pypi.douban.com pandas\nLooking in indexes: https://pypi.douban.com/simple\nWARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pandas/\nWARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pandas/\nWARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pandas/\nWARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pandas/\nWARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pandas/\nERROR: Could not find a version that satisfies the requirement pandas (from versions: none)\nERROR: No matching distribution found for pandas\n
Run Code Online (Sandbox Code Playgroud)\n

我不知道还能去哪里寻找。

\n

更新

\n

使用卷曲测试

\n

使用 访问存储库curl似乎没问题。

\n
\xe2\x9d\xaf curl -v -I https://pypi.douban.com/simple\n*   Trying 140.143.177.206:443...\n* TCP_NODELAY set\n* Connected to pypi.douban.com (140.143.177.206) port 443 (#0)\n* ALPN, offering h2\n* ALPN, offering http/1.1\n* successfully set certificate verify locations:\n*   CAfile: /etc/ssl/certs/ca-certificates.crt\n  CApath: /etc/ssl/certs\n* TLSv1.3 (OUT), TLS handshake, Client hello (1):\n* TLSv1.3 (IN), TLS handshake, Server hello (2):\n* TLSv1.2 (IN), TLS handshake, Certificate (11):\n* TLSv1.2 (IN), TLS handshake, Server key exchange (12):\n* TLSv1.2 (IN), TLS handshake, Server finished (14):\n* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):\n* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):\n* TLSv1.2 (OUT), TLS handshake, Finished (20):\n* TLSv1.2 (IN), TLS handshake, Finished (20):\n* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256\n* ALPN, server accepted to use http/1.1\n* Server certificate:\n*  subject: C=CN; ST=Beijing; O=Beijing Douwang Technology Co. Ltd.; CN=*.douban.com\n*  start date: Jun 22 00:00:00 2022 GMT\n*  expire date: Jul 23 23:59:59 2023 GMT\n*  subjectAltName: host "pypi.douban.com" matched cert\'s "*.douban.com"\n*  issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=GeoTrust RSA CA 2018\n*  SSL certificate verify ok.\n> HEAD /simple HTTP/1.1\n> Host: pypi.douban.com\n> User-Agent: curl/7.68.0\n> Accept: */*\n> \n* Mark bundle as not supporting multiuse\n< HTTP/1.1 301 Moved Permanently\nHTTP/1.1 301 Moved Permanently\n< Date: Thu, 15 Sep 2022 06:38:26 GMT\nDate: Thu, 15 Sep 2022 06:38:26 GMT\n< Content-Type: text/html\nContent-Type: text/html\n< Content-Length: 162\nContent-Length: 162\n< Connection: keep-alive\nConnection: keep-alive\n< Keep-Alive: timeout=30\nKeep-Alive: timeout=30\n< Location: https://pypi.doubanio.com/simple\nLocation: https://pypi.doubanio.com/simple\n< Server: dae\nServer: dae\n\n< \n* Connection #0 to host pypi.douban.com left intact\n
Run Code Online (Sandbox Code Playgroud)\n

OpenSSL 版本

\n
\xe2\x9d\xaf openssl version -a\nOpenSSL 1.1.1f  31 Mar 2020\nbuilt on: Mon Jul  4 11:24:28 2022 UTC\nplatform: debian-amd64\noptions:  bn(64,64) rc4(16x,int) des(int) blowfish(ptr) \ncompiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -Wa,--noexecstack -g -O2 -fdebug-prefix-map=/build/openssl-51ig8V/openssl-1.1.1f=. -fstack-protector-strong -Wformat -Werror=format-security -DOPENSSL_TLS_SECURITY_LEVEL=2 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -DNDEBUG -Wdate-time -D_FORTIFY_SOURCE=2\nOPENSSLDIR: "/usr/lib/ssl"\nENGINESDIR: "/usr/lib/x86_64-linux-gnu/engines-1.1"\nSeeding source: os-specific\n
Run Code Online (Sandbox Code Playgroud)\n

不更新点

\n

它适用于旧版本的 pip20.0.2

\n
\xe2\x9d\xaf ./venv/bin/pip install Pillow\nCollecting Pillow\n  Using cached Pillow-9.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB)\nInstalling collected packages: Pillow\nSuccessfully installed Pillow-9.2.0\n\xe2\x9d\xaf ./venv/bin/pip install numpy\nCollecting numpy\n  Using cached numpy-1.23.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.1 MB)\nInstalling collected packages: numpy\nSuccessfully installed numpy-1.23.3\n\xe2\x9d\xaf ./venv/bin/pip --version\npip 20.0.2\n
Run Code Online (Sandbox Code Playgroud)\n

pip 21.0 带来重大变化

\n

发行说明

\n
\xe2\x9d\xaf ./venv/bin/pip install --upgrade pip==20.3.4\nCollecting pip==20.3.4\n  Using cached pip-20.3.4-py2.py3-none-any.whl (1.5 MB)\nInstalling collected packages: pip\n  Attempting uninstall: pip\n    Found existing installation: pip 20.0.2\n    Uninstalling pip-20.0.2:\n      Successfully uninstalled pip-20.0.2\nSuccessfully installed pip-20.3.4\n\xe2\x9d\xaf ./venv/bin/pip install --upgrade pip==21.0\nWARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pip/\nWARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pip/\nWARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pip/\nWARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pip/\nWARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by \'ProtocolError(\'Connection aborted.\', FileNotFoundError(2, \'No such file or directory\'))\': /simple/pip/\nERROR: Could not find a version that satisfies the requirement pip==21.0\nERROR: No matching distribution found for pip==21.0\nWARNING: You are using pip version 20.3.4; however, version 22.2.2 is available.\nYou should consider upgrading via the \'/home/$USER/git/infrastructure-manual-tasks/cropster-csar/resize-login-images/venv/bin/python3 -m pip install --upgrade pip\' command.\n\n
Run Code Online (Sandbox Code Playgroud)\n