中国服务器上pip安装SSL错误

0 投票
3 回答
3592 浏览
提问于 2025-04-17 23:06

我正在中国的服务器上安装Django,使用的是Ubuntu 12.04。

我尝试运行 pip install django,结果出现了这个错误:

Cannot fetch index base URL http://pypi.pyton.org/simple/
Could not find any downloads that satisfy the requirement django

完整的 pip.log 内容是:

Downloading/unpacking django

  Getting page http://pypi.python.org/simple/django
  Could not fetch URL http://pypi.python.org/simple/django: <urlopen error _ssl.c:489: The handshake operation timed out>
  Will skip URL http://pypi.python.org/simple/django when looking for download links for django
  Getting page http://pypi.python.org/simple/
  Could not fetch URL http://pypi.python.org/simple/: The read operation timed out
  Will skip URL http://pypi.python.org/simple/ when looking for download links for django
  Cannot fetch index base URL http://pypi.python.org/simple/

  URLs to search for versions for django:
  * http://pypi.python.org/simple/django/
  Getting page http://pypi.python.org/simple/django/
  Could not fetch URL http://pypi.python.org/simple/django/: timed out
  Will skip URL http://pypi.python.org/simple/django/ when looking for download links for django
  Could not find any downloads that satisfy the requirement django

No distributions at all found for django

我看到有人说这可能是系统时间和ssl有关的问题,你们知道我该怎么解决吗?我需要设置一个特定的系统时间才能用pip安装软件包吗?

谢谢。

3 个回答

1

你也可以通过全局代理的 goagent 或者使用VPN来运行pip。

更新: http://www.greatfirewallofchina.org/ 可能会报告错误,它刚刚告诉我没有服务器能够访问百度!(而实际上是可以访问的)

4

最近,防火长城的技术越来越厉害,连VPN都很难逃过它的监控。你可能需要使用一个不同的(本地的)镜像来进行pip安装。在我写这段话的时候,这个镜像对我来说是有效的:

pip install [YOUR_PACKAGE] -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com
1

pypi.python.org这个域名似乎被中国的防火墙给屏蔽了,想了解更多信息可以查看这里 - http://en.wikipedia.org/wiki/Golden_Shield_Project。如果你想测试某个网站在中国能不能打开,可以去这个网站 http://www.greatfirewallofchina.org,它可以确认网站是否被屏蔽:http://www.greatfirewallofchina.org/index.php?siteurl=http%3A%2F%2Fpypi.python.org

你可以尝试以下方法:

  1. 试试使用Ubuntu自带的软件包,直接用apt-get安装Django(输入命令 $ sudo apt-get install python-django)。
  2. 在其他国家下载Django的pip压缩包,然后把这个文件复制到你在中国的服务器上。关于如何使用pip压缩包的更多信息可以查看这里 Installing Python packages from local file system folder with pip

撰写回答