Step 2: Make sure that python is installed on the local machine. Download easy_install to a local directory and double-click ez_setup.py. python will be automatically downloaded to the python installation directory/Scripts, then add the directory where easy_install is located in the PATH of the system environment variable, for example, C: \ Python27 \ Scripts.
Step 2: Install virtualenv, which is mainly used to isolate the interpreter environment and avoid multiple python or multiple python library dependencies on the same machine. The installation commands for various operating systems are as follows:
Linux and mac OS x:
Sudo easy_install virtualenv
Or sudo pip install virtualenv
For ubuntu, you can
Sudo apt-get install python-virtualenv
In windows, run the following command in the python shell window:
Easy_install virtualenv
Step 2: Use virtualenv to create a python virtual environment. We may need to run and test the Flask project in this environment.
In Linux:
$ Mkdir myproject
$ Cd myproject
$ Virtualenv env
New python executable in env/bin/python
Installing setuptools.
Then activate:
$. Env/bin/activate
Creating a python virtual environment in Windows is simpler. Switch to the dos mode and run the following command:
> Cd D:
> Virtualenv myvir
After the creation, you will find that there will be an additional myvir directory under the d directory, switch to the directory Scripts directory in DOS mode, and execute
> Activate. bat
To activate the virtual environment.
After activating the virtual environment, we can officially install Flask in it.
Linux
$ Easy_install Flask
Windows
Easy_install Flask
The installation is complete.
Finally, let's test it.
View plaincopy to clipboardprint?
from flask import Flask app = Flask(__name__) @app .route('/') def hello_world(): return "Hello World!" if __name__ == '__main__': app.run()
Save it as hello. py or other similar file names, and then run the file in the activated myvir python interpreter (ensure that the program name is not flask. py, which will conflict with Flask itself)
$ Python hello. py
* Running on http: // 127.0.0.1: 5000/
Open the URL http: // 127.0.0.1: 5000/. Have you seen the familiar hello world greetings :)