Install python Flask

Source: Internet
Author: User
Tags virtualenv

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 :)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.