首页 » 编程开发 » Python » 正文

Python中pip/setup安装插件失败提示“pypi.python.org” 打不开的解决办法

经常在安装python安装包的时候提示安装失败,仔细查看失败原因,发现是网站pypi.python.org访问超时导致的,比如:

Installed f:\fortest\python\lib\site-packages\wechat_sdk-0.5.8-py2.7.egg
Processing dependencies for wechat-sdk==0.5.8
Searching for requests>=2.6.0
Reading https://pypi.python.org/simple/requests/
Download error on https://pypi.python.org/simple/requests/: _ssl.c:489: The handshake operation timed out — Some packages may not be found!
Couldn’t find index page for ‘requests’ (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: _ssl.c:489: The handshake operation timed out — Some packages may not be found!
No local packages or download links found for requests>=2.6.0
error: Could not find suitable distribution for Requirement.parse(‘requests>=2.6.0’)

不管是pip安装还是pip命令安装,或者自己手动下载后安装,都有可能碰到这个问题,主要原因就是网站pypi.python.org在国内是被墙了的,在安装程序的时候,无法从python官网下载资料导致的。
解决这个问题的方法,就是用国内的镜像资料库替换pypi.python.org,本文尝试将资料库下载地址替换成豆瓣的源。

pip命令安装

在pip工具的安装目录找到配置文件~/.pip/pip.conf,在里面添加如下代码:

[global]
index-url = http://pypi.douban.com/simple

配置完成,接着就可以开始运行pip命令进行安装了。如果在pip目录下没找到文件php.conf,那么我们也可以使用pip命令安装的时候手动指定源地址:

pip install web.py -i http://pypi.douban.com/simple

setup.py手动安装

在setup.py文件的同级目录下,新建文件setup.cfg,在文件中加入如下代码:

[easy_install]
index_url = http://pypi.douban.com/simple

完成之后,运行命令“python setup.py install” ,成功安装。

本文共 1 个回复

  • tonight with boy abunda, 2017/12/28 00:39

    I have learn some excellent stuff here. Definitely worth bookmarking for revisiting. I wonder how much effort you put to create any such excellent informative website.

发表评论