Flask 简明教程
Flask – Environment
Prerequisite
通常需要 Python 2.6 或更高版本才能安装 Flask。尽管 Flask 及其依赖项可与 Python 3 配合良好 (Python 3.3 及更高版本),但许多 Flask 扩展都不支持它。因此,建议在 Python 2.7 上安装 Flask。
Python 2.6 or higher is usually required for installation of Flask. Although Flask and its dependencies work well with Python 3 (Python 3.3 onwards), many Flask extensions do not support it properly. Hence, it is recommended that Flask should be installed on Python 2.7.
Install virtualenv for development environment
virtualenv 是一个虚拟 Python 环境构建程序。它帮助用户并行创建多个 Python 环境。因此,它可以避免不同版本库之间的兼容性问题。
virtualenv is a virtual Python environment builder. It helps a user to create multiple Python environments side-by-side. Thereby, it can avoid compatibility issues between the different versions of the libraries.
以下命令可安装 virtualenv
The following command installs virtualenv
pip install virtualenv
此命令需要管理员权限。在 Linux/Mac OS 上,添加 sudo pip 前。如果使用的是 Windows,请以管理员身份登录。在 Ubuntu 上,可以使用其软件包管理器来安装 virtualenv 。
This command needs administrator privileges. Add sudo before pip on Linux/Mac OS. If you are on Windows, log in as Administrator. On Ubuntu virtualenv may be installed using its package manager.
Sudo apt-get install virtualenv
安装后,会在文件夹中创建一个新的虚拟环境。
Once installed, new virtual environment is created in a folder.
mkdir newproj
cd newproj
virtualenv venv
要在 Linux/OS X 激活相应环境,请使用以下内容 -
To activate corresponding environment, on Linux/OS X, use the following −
venv/bin/activate
在 Windows 上,可以使用以下内容
On Windows, following can be used
venv\scripts\activate
现在我们可以准备在此环境中安装 Flask。
We are now ready to install Flask in this environment.
pip install Flask
可直接运行以上命令,无需用于系统级安装的虚拟环境。
The above command can be run directly, without virtual environment for system-wide installation.