为什么 pip3 在安装包时抛出错误?

为什么 pip3 在安装包时抛出错误?

我正在使用 Kubuntu。

我无法使用 pip 安装任何软件包。我卸载了 pip 并重新安装,重启了电脑、网络连接和终端。但问题仍然存在。我的网络连接没有问题。

如果你们能给出逐步的解决方案,那将会非常有帮助。

samip@samip-Inspiron-3521:~$ pip3 install pygame

Collecting pygame
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. (read timeout=15)")': /packages/0f/9c/78626be04e193c0624842090fe5555b3805c050dfaa81c8094d6441db2be/pygame-1.9.6.tar.gz
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. (read timeout=15)")': /packages/0f/9c/78626be04e193c0624842090fe5555b3805c050dfaa81c8094d6441db2be/pygame-1.9.6.tar.gz
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. (read timeout=15)")': /packages/0f/9c/78626be04e193c0624842090fe5555b3805c050dfaa81c8094d6441db2be/pygame-1.9.6.tar.gz
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. (read timeout=15)")': /packages/0f/9c/78626be04e193c0624842090fe5555b3805c050dfaa81c8094d6441db2be/pygame-1.9.6.tar.gz
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. (read timeout=15)")': /packages/0f/9c/78626be04e193c0624842090fe5555b3805c050dfaa81c8094d6441db2be/pygame-1.9.6.tar.gz

ERROR: Could not install packages due to an EnvironmentError: 
HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url:
 /packages/0f/9c/78626be04e193c0624842090fe5555b3805c050dfaa81c8094d6441db2be/pygame-
1.9.6.tar.gz (Caused by ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org', 
port=443): Read timed out. (read timeout=15)"))

答案1

正如 Nomi Shaw 所说,您的问题似乎是互联网连接不稳定。

另外,请不要直接使用 pip 或 pip3 将第三方包安装到全局 Python 解释器中。

请首先创建并激活虚拟环境。

RealPython.com 有一篇关于为什么和如何做的精彩文章:

https://realpython.com/python-virtual-environments-a-primer/

答案2

除了 Nomi Shaw 和 jugmac00 所说的,几个月前我也遇到过同样的问题,这让我抓狂不已。我不知道您遇到同样问题的可能性有多大,但以防万一:

我的错误是由我安装的互联网过滤器引起的(普鲁克耶) 事实证明,它不仅阻止了我的浏览器连接,还阻止了我所有的其他连接(pip、calibre、r……)。一旦我将其设置为较低的限制级别,一切都会正常工作!

相关内容