码迷,mamicode.com
首页 > 编程语言 > 详细

window下python 扩展库安装 使用第三方镜像源

时间:2014-06-24 09:59:22      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:class   blog   code   http   tar   ext   

0.前言
    由于python的官方镜像位于国外,若使用pip或者easy_install安装第三方插件时或许会被限制,甚至连easy_install或pip也无法安装,例如在windows环境下运行ez_setup.py 安装easy_install,可能遇到下图这样尴尬的情况。
bubuko.com,布布扣
图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 plaincopybubuko.com,布布扣bubuko.com,布布扣
 
  1. import requests  
  2. r=requests.get("http://www.sina.com.cn")  
  3. r.status_code  

window下python 扩展库安装 使用第三方镜像源,布布扣,bubuko.com

window下python 扩展库安装 使用第三方镜像源

标签:class   blog   code   http   tar   ext   

原文地址:http://www.cnblogs.com/jacker1979/p/3799173.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!