學(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去翻~~一墻, 有了目的性搜索很快就搜索到了, 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)境了。
#!/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即可。
|
|