第一章《Flask Web开发》:安装flask

flaskGithub

阿里云服务器
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协议与HTTPS协议
    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

快速入门

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • # Python 资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列...
    小迈克阅读 8,178评论 1 3
  • 【百度云搜索,搜各种资料:http://bdy.lqkweb.com】 【搜网盘,搜各种资料:http://www...
    攻城狮笔记阅读 8,802评论 0 9
  • 不要盲目崇拜,不要迷信权威,要经过独立思索和独立判断;要保持怀疑精神,保持探索精神。
    Albert_Bruce阅读 1,090评论 0 1
  • 少年时,我们倾向于做生命的链接。喜爱玩伴,寻求朋友。老年时,我们做自身的圆融。一个人一番别样的天地,静观万物皆自得。
    百花里的浮想阅读 1,409评论 0 0
  • 重庆公交车坠江事故的真相出来了,原来是一名错过站的乘客和司机之间的不理智争执,导致车辆失控,酿成了惨剧。15条鲜活...
    格致教练蒋海涛阅读 4,121评论 0 0

友情链接更多精彩内容