首页 > 代码库 > window下python 扩展库安装 使用第三方镜像源
window下python 扩展库安装 使用第三方镜像源
0.前言
由于python的官方镜像位于国外,若使用pip或者easy_install安装第三方插件时或许会被限制,甚至连easy_install或pip也无法安装,例如在windows环境下运行ez_setup.py 安装easy_install,可能遇到下图这样尴尬的情况。
图1 运行ez_setup.py失败
遇到这种问题可以”转战“国内的第三方镜像,问题便可迎刃而解。例如豆瓣镜像——http://pypi.douban.com/simple/
1.安装easy_install
先安装easy_install,有了这个工具便可安装其他的python扩展库。工具网址——http://pypi.douban.com/simple/setuptools/
在该网页中选择合适的版本,例如本机中的python版本为2.7.6,操作系统为windows,那么应选择 setuptools-0.6c11.win32-py2.7.exe
顺利安装完easy_install之后,应把easy_install加入环境变量。easy_install.exe位于python安装目录的script文件夹下。(别告诉我你不会修改环境变量)
2.使用easy_install安装扩展库
例如安装requests扩展库(一种简单实用的HTTP通信工具),那么可以在控制台中输入以下命令
转入Python的安装目录下的Scripts目录后运行如下命令:
easy_install -i http://pypi.douban.com/simple/ requests
easy_install -i 选项可以设置镜像网址,这里指定到国内的豆瓣镜像。安装需要一些时间,不过只用您等待一小会。
安装完之后可尝试安装是否成功,可以通过以下python测试:
若执行正确,那么status_code的结果应为200
[python] view plaincopy
- import requests
- r=requests.get("http://www.sina.com.cn")
- r.status_code
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。