一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

使用國(guó)內(nèi)鏡像通過(guò)pip安裝python的一些包 | 學(xué)步園

 bubbi7 2017-06-27

學(xué)習(xí)flask,安裝virtualenv環(huán)境,這些帶都o(jì)k,但是一安裝包總是出錯(cuò)無(wú)法安裝,

比如這樣超時(shí)的問(wèn)題:

(env)user@orz:~/flask_study/venv-test/test$ easy_install Flask-SQLAlchemy
Searching for Flask-SQLAlchemy
Reading http://pypi./simple/Flask-SQLAlchemy/
Best match: Flask-SQLAlchemy 1.0
Downloading https://pypi./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./simple/SQLAlchemy/
Download error on http://pypi./simple/SQLAlchemy/: _ssl.c:489: The handshake operation timed out -- Some packages may not be found!
Reading http://pypi./simple/SQLAlchemy/
Best match: SQLAlchemy 0.8.2
Downloading https://pypi./packages/source/S/SQLAlchemy/SQLAlchemy-0.8.2.tar.gz#md5=5a33fb43dea93468dbb2a6562ee80b54
error: Download error for https://pypi./packages/source/S/SQLAlchemy/SQLAlchemy-0.8.2.tar.gz: _ssl.c:489: The handshake operation timed out

或者這種:

(env)user@orz:~/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./simple/

或者:

Downloading/unpacking Jinja2>=2.4 (from flask)
  Error The read operation timed out while getting https://pypi./packages/source/J/Jinja2/Jinja2-2.7.1.tar.gz#md5=282aed153e69f970d6e76f78ed9d027a (from https://pypi./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 = (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, _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, wnload_cache, wnload_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 _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

為什么總是失???自己操作老標(biāo)準(zhǔn)了,這么簡(jiǎn)單的幾個(gè)小步驟還老是出錯(cuò),不由得讓我懷疑是否是撞墻了,可是又懶得買(mǎi)vpn去翻~~一墻,
無(wú)法代理又無(wú)法翻~~一墻,被逼著想到了使用鏡像的方法了,一些公共的網(wǎng)站在國(guó)內(nèi)總有一些鏡像,使用這些鏡像地址來(lái)安裝就可以了

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

http://e.pypi./這個(gè)就是官網(wǎng)了,清華大學(xué)提供的

建議非清華大學(xué)校內(nèi)的使用這個(gè)鏡像: http://e.pypi./simple(這也是一個(gè)http://pypi./simple),清華校內(nèi)的就使用這個(gè):http://mirrors.tuna./pypi/simple


使用鏡像的方法可以在每次執(zhí)行pip的時(shí)候加上參數(shù)"-i http://e.pypi./simple"即可,

或者也可以在本地配置,這樣就不用每次都加上參數(shù)了,應(yīng)用Cheer Xiao的配置(http://blog./post/2012-11-01/pypi-mirror):

使用pip的用戶(hù)可以如下配置:

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

需要在配置文件內(nèi)加上:

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

還有一個(gè)小技巧,就是把所有要安裝的包寫(xiě)在一個(gè)文件里面,比如requirement.txt(每個(gè)包寫(xiě)一行,頂行頭寫(xiě)),然后pip安裝的時(shí)候只需要加參數(shù)“-r  requirement.txt”即可。

安裝好之后體驗(yàn)了一把,速度颼颼的,感覺(jué)就一個(gè)字:爽~~

ps:

    使用步驟:

          1.進(jìn)入目錄下使用命令:virtualenv env

        2.source env/bin/activate,這時(shí)候你會(huì)發(fā)現(xiàn)命令行前面會(huì)多出個(gè)(env)標(biāo)識(shí),這表明你已經(jīng)進(jìn)入了虛擬環(huán)境了。

         寫(xiě)個(gè)簡(jiǎn)單的驗(yàn)證:

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

app = Flask(__name__)

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

if __name__ == '__main__':
    ()

提示沒(méi)有flask包,使用上面的方法pip之,pip install  -i http://e.pypi./simple  flask,速度超快,安裝之,運(yùn)行,OK。

解惑:為什么這樣安裝酒OK了?而且不會(huì)對(duì)系統(tǒng)的原有的包造成影響?

查看env目錄下的內(nèi)容,發(fā)現(xiàn)在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                                markupsafe                      werkzeug
flask                        c                  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

這就是虛擬機(jī)的作用了。

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

(決定以后每篇文章都先放一張搞笑的圖,讓自己樂(lè)呵一下)

#2013.08.27

直接安裝flask會(huì)安裝最新0.10的版本,很悲劇的是很多擴(kuò)展包還沒(méi)跟上此版本,所以很多功能沒(méi)法用哦~~比如Falsk-Mail的版本

所以還是重新安裝Flask的0.9版本,不過(guò)這也不是個(gè)事,有了envitualenv后環(huán)境非常容易,今天試了 -i http://e.pypi./simple竟然不行了 = =!,找到這個(gè)鏡像地址不錯(cuò)http://pypi./simple

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

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多

    欧美六区视频在线观看| 深夜视频在线观看免费你懂| 中文字幕人妻一区二区免费| 熟女少妇久久一区二区三区| 亚洲高清欧美中文字幕| 东京热男人的天堂一二三区| 国内精品一区二区欧美| 97人妻精品免费一区二区| 99秋霞在线观看视频| 免费啪视频免费欧美亚洲| 国产精品午夜一区二区三区| 日本本亚洲三级在线播放| 久久精品亚洲精品一区| 97人妻精品一区二区三区男同| 日韩人妻有码一区二区| 老熟妇2久久国内精品| 99久久国产精品成人观看| 亚洲精品有码中文字幕在线观看| 久久精品久久精品中文字幕| 高清不卡视频在线观看| 超碰在线播放国产精品| 亚洲国产香蕉视频在线观看| 国产91色综合久久高清| 日本99精品在线观看| 国产精品香蕉免费手机视频| 日本人妻免费一区二区三区| 日本不卡在线视频中文国产| 美国女大兵激情豪放视频播放| 国产成人亚洲综合色就色| 国产日韩欧美国产欧美日韩| 国产精品久久三级精品| 色哟哟在线免费一区二区三区| 国产午夜福利一区二区| 亚洲精品深夜福利视频| 国内欲色一区二区三区| 欧美日韩精品久久第一页| 欧美日韩精品综合在线| 国产精品激情对白一区二区| 成人欧美一区二区三区视频| 天海翼精品久久中文字幕| 国产精品人妻熟女毛片av久久|