阿里云服务器
Python
1.1 使用虚拟环境
我已经安装好了:
$ virtualenv --version
15.1.0
安装了Git,也是第一次用。
git clone https://github.com/miguelgrinberg/flasky.git
cd flasky/
git checkout 1a
当我试图按照书上从GitHub上下载示例代码的时候,出现了下面的报错:
Initialized empty Git repository in /home/zhouyunlai/Python/project.git/flasky/.git/
error: while accessing https://github.com/miguelgrinberg/flasky.git/info/refs
fatal: HTTP request failed
查了之后可能是HTTPS协议不行,用Git协议,在GitHub上获取Git协议地址:
git clone git@github.com:miguelgrinberg/flasky.git
得到了如下报错:
Initialized empty Git repository in /home/zhouyunlai/Python/flasky/.git/
The authenticity of host 'github.com (13.229.188.59)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.229.188.59' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
看了github提示Permission denied (publickey),如何才能解决?按照里面的步骤配置了一下GitHub的SSH Keys,试了一下
git clone git@github.com:miguelgrinberg/flasky.git
还是不行:
Initialized empty Git repository in /home/zhouyunlai/Python/flasky/.git/
Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.
Connection closed by 52.74.223.119
fatal: The remote end hung up unexpectedly
查了git push 时出现Connection closed by remote host文章没看完,就把下面的代码输进去了 :
ssh git@github.com -vT
输出一堆结果。然后再试一下,可以了:
git clone git@github.com:miguelgrinberg/flasky.git
Initialized empty Git repository in /home/zhouyunlai/Python/flasky/.git/
remote: Counting objects: 896, done.
remote: Total 896 (delta 0), reused 0 (delta 0), pack-reused 895
Receiving objects: 100% (896/896), 179.20 KiB, done.
Resolving deltas: 100% (541/541), done.
接着按步骤来:
$ virtualenv venv
New python executable in /home/zhouyunlai/Python/flasky/venv/bin/python
/home/zhouyunlai/Python/flasky/venv/bin/python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
ERROR: The executable /home/zhouyunlai/Python/flasky/venv/bin/python is not functioning
ERROR: It thinks sys.prefix is u'/home/zhouyunlai/Python/flasky' (should be u'/home/zhouyunlai/Python/flasky/venv')
ERROR: virtualenv is not compatible with this system or executable
不出所料,每一个新的命令都会报错。看了廖雪峰的virtualenv还是不管用。
你不是没有libpython2.7.so.1.0 吗?我找几个出来:
find / -name libpython2.7.so.1.0
/usr/local/aegis/PythonLoader/lib/libpython2.7.so.1.0
/usr/local/aegis/PythonLoader/libpython2.7.so.1.0
/root/miniconda2/lib/libpython2.7.so.1.0
/root/miniconda2/pkgs/python-2.7.14-hc2b0042_21/lib/libpython2.7.so.1.0
然后
export LD_LIBRARY_PATH="/root/miniconda2/lib"
$virtualenv venv
New python executable in /home/zhouyunlai/Python/flasky/venv/bin/python
Installing setuptools, pip, wheel...done.
至少没报错了。
在使用虚拟环境之前,需要先激活:
source venv/bin/activate
命令行前面出现了(venv),应该可以了。
1.2 使用pip安装Python包
在虚拟环境中安装Flask
$ pip install flask
启动Python解释器,尝试导入Flask
$python
Python 2.7.14 |Anaconda, Inc.| (default, Oct 16 2017, 17:29:19)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
没有报错,成功了。可以学习第二章了。
今天的工作完成,回到全局Python解释器中;
deactivate
Linux及Git介绍
阿里云 linux搭建git服务器
《Flask Web Development》第1章 安装Flask