使用國內鏡像通過pip安裝python的一些包 Cannot fetch index base URL http://pypi.python.org/simple/

原文地址:http://www.xuebuyuan.com/1157602.html

学习flask,安装virtualenv环境,这些带都ok,但是一安装包总是出错无法安装,

比如这样超时的问题:

 

(env)[email protected]:~/flask_study/venv-test/test$ easy_install Flask-SQLAlchemy
Searching for Flask-SQLAlchemy
Reading http://pypi.python.org/simple/Flask-SQLAlchemy/
Best match: Flask-SQLAlchemy 1.0
Downloading https://pypi.python.org/packages/source/F/Flask-SQLAlchemy/Flask-SQLAlchemy-1.0.tar.gz#md5=dca034849ffcbaef7b848e8728d3668f
Processing Flask-SQLAlchemy-1.0.tar.gz
Running Flask-SQLAlchemy-1.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-lQ6xtl/Flask-SQLAlchemy-1.0/egg-dist-tmp-ZojgvG
warning: no previously-included files matching '*.pyc' found under directory 'docs'
warning: no previously-included files matching '*.pyo' found under directory 'docs'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'docs/_themes/.git'
Adding Flask-SQLAlchemy 1.0 to easy-install.pth file

Installed /home/zt/flask_study/venv-test/test/env/lib/python2.7/site-packages/Flask_SQLAlchemy-1.0-py2.7.egg
Processing dependencies for Flask-SQLAlchemy
Searching for SQLAlchemy
Reading http://pypi.python.org/simple/SQLAlchemy/
Download error on http://pypi.python.org/simple/SQLAlchemy/: _ssl.c:489: The handshake operation timed out -- Some packages may not be found!
Reading http://pypi.python.org/simple/SQLAlchemy/
Best match: SQLAlchemy 0.8.2
Downloading https://pypi.python.org/packages/source/S/SQLAlchemy/SQLAlchemy-0.8.2.tar.gz#md5=5a33fb43dea93468dbb2a6562ee80b54
error: Download error for https://pypi.python.org/packages/source/S/SQLAlchemy/SQLAlchemy-0.8.2.tar.gz: _ssl.c:489: The handshake operation timed out

 

 

或者这种:

(env)[email protected]:~/flask_study/venv-test/test$ pip install flask
Downloading/unpacking flask
  Could not find any downloads that satisfy the requirement flask
No distributions at all found for flask
Storing complete log in /home/user/.pip/pip.log

 

 

或者:

 

Downloading/unpacking flask
  Cannot fetch index base URL http://pypi.python.org/simple/

 

或者:

Downloading/unpacking Jinja2>=2.4 (from flask)
  Error The read operation timed out while getting https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.7.1.tar.gz#md5=282aed153e69f970d6e76f78ed9d027a (from https://pypi.python.org/simple/Jinja2/)
Exception:
Traceback (most recent call last):
  File "/home/user/flask_study/venv-test/test/env/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/basecommand.py", line 104, in main
    status = self.run(options, args)
  File "/home/user/flask_study/venv-test/test/env/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/commands/install.py", line 245, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/home/user/flask_study/venv-test/test/env/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/req.py", line 985, in prepare_files
    self.unpack_url(url, location, self.is_download)
  File "/home/user/flask_study/venv-test/test/env/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/req.py", line 1109, in unpack_url
    retval = unpack_http_url(link, location, self.download_cache, self.download_dir)
  File "/home/user/flask_study/venv-test/test/env/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.py", line 431, in unpack_http_url
    resp = _get_response_from_url(target_url, link)
  File "/home/user/flask_study/venv-test/test/env/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.py", line 466, in _get_response_from_url
    resp = urlopen(target_url)
  File "/home/user/flask_study/venv-test/test/env/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.py", line 85, in __call__
    response = urllib2.urlopen(self.get_request(url))
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 401, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 419, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 379, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1219, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
    r = h.getresponse(buffering=True)
  File "/usr/lib/python2.7/httplib.py", line 1034, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 407, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 365, in _read_status
    line = self.fp.readline()
  File "/usr/lib/python2.7/socket.py", line 447, in readline
    data = self._sock.recv(self._rbufsize)
  File "/usr/lib/python2.7/ssl.py", line 241, in recv
    return self.read(buflen)
  File "/usr/lib/python2.7/ssl.py", line 160, in read
    return self._sslobj.read(len)
SSLError: The read operation timed out

Storing complete log in /home/user/.pip/pip.log

为什么总是失敗?自己操作老标准了,这么简单的几个小步骤还老是出错,不由得让我怀疑是否是撞墙了,可是又懒得买vpn去翻~~一墙,
无法代理又无法翻~~一墙,被逼着想到了使用镜像的方法了,一些公共的网站在国内总有一些镜像,使用这些镜像地址来安装就可以了

有了目的性搜索很快就搜索到了,

http://e.pypi.python.org/这个就是官网了,清华大学提供的

建议非清华大学校内的使用这个镜像: http://e.pypi.python.org/simple(这也是一个http://pypi.v2ex.com/simple),清华校内的就使用这个:http://mirrors.tuna.tsinghua.edu.cn/pypi/simple

 

使用镜像的方法可以在每次执行pip的时候加上参数"-i http://e.pypi.python.org/simple"即可,

或者也可以在本地配置,这样就不用每次都加上参数了,应用Cheer Xiao的配置(http://blog.makto.me/post/2012-11-01/pypi-mirror):

 

使用pip的用户可以如下配置:

在unix和macos,配置文件为:$HOME/.pip/pip.conf
在windows上,配置文件为:%HOME%\pip\pip.ini

需要在配置文件内加上:

[global]
index-url=http://mirrors.tuna.tsinghua.edu.cn/pypi/simple

还有一个小技巧,就是把所有要安装的包写在一个文件里面,比如requirement.txt(每个包写一行,顶行头写),然后pip安装的时候只需要加参数“-r  requirement.txt”即可。

 

安装好之后体验了一把,速度飕飕的,感觉就一个字:爽~~

 

ps:

    使用步骤:

          1.进入目录下使用命令:virtualenv env

        2.source env/bin/activate,这时候你会发现命令行前面会多出个(env)标识,这表明你已经进入了虚拟环境了。

         写个简单的hello.py验证:

 

#!/usr/bin/python
from flask import Flask

app = Flask(__name__)

@app.route('/', methods = ['GET', 'POST'])
def hello():
    return 'Hello world!'

if __name__ == '__main__':
    app.run()

提示没有flask包,使用上面的方法pip之,pip install  -i http://e.pypi.python.org/simple  flask,速度超快,安装之,运行,OK。

解惑:为什么这样安装酒OK了?而且不会对系统的原有的包造成影响?

查看env目录下的内容,发现在env/lib/pythonX.X/site-packages目录下有这些安装的包,比如我的下面有这些:

 

distribute-0.6.24-py2.7.egg  itsdangerous-0.23-py2.7.egg-info  Jinja2-2.7.1-py2.7.egg-info     setuptools.pth
easy-install.pth             itsdangerous.py                   markupsafe                      werkzeug
flask                        itsdangerous.pyc                  MarkupSafe-0.18-py2.7.egg-info  Werkzeug-0.9.3-py2.7.egg-info
Flask-0.10.1-py2.7.egg-info  jinja2                            pip-1.1-py2.7.egg

这就是虚拟机的作用了。

 

 

终于可以安心的把精力集中到flask上了。

 

 

(决定以后每篇文章都先放一张搞笑的图,让自己乐呵一下)

 

 

 

 

#2013.08.27

直接安装flask会安装最新0.10的版本,很悲剧的是很多扩展包还没跟上此版本,所以很多功能没法用哦~~比如Falsk-Mail的版本

所以还是重新安装Flask的0.9版本,不过这也不是个事,有了envitualenv后环境非常容易,今天试了 -i http://e.pypi.python.org/simple竟然不行了 = =!,找到这个镜像地址不错http://pypi.v2ex.com/simple

哦,安装Flask0.9版本也很容易,直接pip install Flask==0.9即可。

配置入下

gedit ~/.pip/pip.conf 然后

使用國內鏡像通過pip安裝python的一些包   Cannot fetch index base URL http://pypi.python.org/simple/

更多相关文章
  • 1.首先要把nginx的apt源加入到/etc/apt/source.list中去 Debian7 (wheezy) deb http://nginx.org/packages/debian/ wheezy nginx deb-src http://nginx.org/packages/debian
  • 


    		    通過Internet安裝KVM虛擬機
    1.创建虚拟机,选中Network Install(HTTP,FTP, or NFS):
  • 在Centos 5.5中安装Nginx+jdk+mysql+tomcat是非常容易的.只需yum安装环境包和nginx.解压安装jdk和tomcat.配置profile文件.server.xml和nginx.conf文件即可.具体步骤如下 可参考 http://www.jforum.com.cn/p ...
  • 


    		    http五之通過rpm安裝lamp程序,並創建虛擬主機
    本文主要讲述如何通过rpm安装lamp程序,并通过wordpress discuz phpwind创建论坛,并通过phpmyadmin来管理mysql数据库,关于lamp的源码安装与mysql的使用将会在后续推出,敬请期待 一.rpm安装lamp程序 我们需要安装的程序包为httpd php php
  • 


    		    通過pxe安裝vmware esxi
    1.文件准备: 在C盘下新建一个文件夹,如pxe,在pxe文件夹下新建pxelinux.c
  • 


    		    ESXi5.5交互式安裝(二)通過USB安裝
    上一遍博文说了通过刻录好的CD/DVD来安装ESXi,今天给大家说一下通过USB来安装ESXi 准备工具: 在VMware官网下载ESXi5.5安装ISO文件(本文以VMware-VMvisor-Installer-5.5.0.update02-2068190.x86_64.iso为例) USB存储
  • 通過cygwin安裝openSSH
    openSSH的安装是学习hadoop必不可少的一步,如果ssh装不好,hadoop的安装
  • 通过ambari安装hadoop集群,ZT http://www.cnblogs.com/cenyuhai/p/3295635.html http://www.cnblogs.com/cenyuhai/p/32956
一周排行
  • 转自: http://www.cnblogs.com/wxf0701/archive/2008/08/17/1269798.html 1.HTTP请求格式: <request line> <head ...
  • 向表中插入数据时可能会报“ORA-00913:值过多”错误,造成这一错误的原因一般是因为字段个数不匹配,例如: insert into table_1 (?, ?) values (?, ?, ?) 插入值比字段多了 ...
  • 劍指Offer面試題:18.二叉樹的鏡像
    一.题目:二叉树的镜像 题目:请完成一个函数,输入一个二叉树,该函数输出它的镜像.例如下图
  • Container With Most Water Given n non-negative integers a1, a2, ..., an, where each represents a point at co
  • 在做项目的时候,在sql中使用了hashbytes函数,运用md5算法去加密一密码.代码如下 DECLARE @psw nvarchar(20) SET @psw = 'admin' SELECT hashbytes
  • 


    		    vCenter CapacityIQ
    VMware vCenter CapacityIQ为过去.当前以及未来的基础架构容量提供了
  • yield是跟return一起使用的,形式为yield return xxx,一般来说单独的return在每个方法中只能存在一个.而yield则不同的是,可以出现连续多个.如 class A : IEnumerabl
  • package cn.itcast.utils; import java.io.InputStream;import java.sql.Connection;import java.sql.DriverManager
  • 1.通过setValue:forKey:为对象属性赋值时,属性的真正类型是由value的类型决定,, 例: @property (nonatomic, strong) NSString  *praise; [self
  • DECLARE @dt datetime SET @dt=GETDATE() DECLARE @number int SET @number=3 --1.指定日期该年的第一天或最后一天 --A. 年的第一天 SELE ...