python-3.x - 无法安装 matplotlib 也无法升级 pip

标签 python-3.x ubuntu pip connection-refused

我在装有 Ubuntu 18.04 的笔记本电脑上使用 python 3.6.5,尽管我也有 Python 2.7.15rc1。在尝试安装 matplotlib 之前,我运行了:

sudo apt-get update && sudo apt-get upgrade

执行没有错误。

然后我尝试通过运行以下命令为 python 3 安装 matplotlib:

python3 -m pip install matplotlib

这产生了一条很长的错误消息,下面重复了该消息:

Collecting matplotlib
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/matplotlib/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/matplotlib/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/matplotlib/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/matplotlib/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/matplotlib/
  Could not find a version that satisfies the requirement matplotlib (from versions: )
No matching distribution found for matplotlib
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

看到最后那条消息,我决定接受,但指定我想要安装 python3。所以我运行了以下命令:

python3 -m pip install --upgrade pip

同样失败,并显示以下消息:

Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/pip/
Collecting pip
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl
Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (Caused by ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')))

You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

基于 this answer ,我运行了 curl https://bootstrap.pypa.io/get-pip.py,但我没有将它传递给 python3,而是检查了输出,不幸的是它只是说:

curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to bootstrap.pypa.io:443 

此时我猜这是一个连接问题,但我在 Firefox 上访问互联网没有问题(我现在甚至发布了这个)...

我已连接到葡萄牙的家用 wi-fi 路由器,并且我没有使用任何代理(根据 Ubuntu 的网络设置)。

根据 this suggestion 禁用 ipv6 , 没有任何帮助。

在我的命令前添加 sudo -H 没有解决问题。

运行 sudo ufw allow 443 后,命令 python3 -m pip install --upgrade pip 现在返回:

Collecting pip
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl
  Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 2.9MB/s 
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/bin/pip'
Consider using the `--user` option or check the permissions.

You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

添加 sudo -H 也不能解决这个问题。我不知道我应该如何使用 --user 选项。

我该怎么办?

最佳答案

这似乎是我连接到互联网的问题,尽管我仍然想了解更多信息。

在 friend 家连接到互联网解决了这个问题。

关于python-3.x - 无法安装 matplotlib 也无法升级 pip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51585393/

相关文章:

android - Ubuntu/Elementary OS 无法设置 ANDROID_HOME

python - 如何使用 pip 1.5(在 Python 上)安装和升级外部托管的包存储库?

Python:检查导入模块时出现运行时错误的原因是什么?

python-3.x - TensorFlow 中更快的 K-Means 聚类

python - 使文件处理代码与 asyncio 兼容

python - 使用 Python 在桌面墙纸上渲染/绘图(在带有 Gnome 的 Ubuntu 中)

python - urlparse 不会为无效的 url 引发异常

linux - UDP 通信在 Linux 上丢失,在使用 C# .NET Core 2.1 时,与 Windows 相比, "UDP sockets"在 Linux 上的管理方式是否不同?

python - 为什么 pip 始终无法安装 pytest-django? .dist-info 目录未找到错误

python - 模块未找到错误: No module named 'imblearn'