How to create an app on Linux using Python and flask

Source: Internet
Author: User
Tags virtual environment

Whether you're entertaining or working on Linux, this is a great opportunity for you to program with python and a zero-based learning Python development ( http://www.maiziedu.com/course/python/ a good opportunity to learnPyhon is interesting and useful in practical applications such as the Yum Package Manager.

To share a great tutorial with you, this tutorial will take you through python and a mini-frame called flask to build a simple application that shows things like Useful information such as memory usage per process,CPU percentage, and so on.

Front-facing requirements

Python Basics, lists, classes, functions, modules. html/css ( basic ).

You don't need to be a python advanced Developer to learn this tutorial, but first I suggest you read the official documentation and learn the basics of python on the official website.

Installing Python 3 on Linux

Python is installed by default on most Linux distributions. The following command allows you to see the installed version.

[Email protected] ~]# python-v

Python 2.7.5

We will use the 3.x version to build our app. According to python.org, this version is now only improved and is not backwards compatible with Python 2.

Note : Before you start, I strongly recommend that you try this tutorial in a virtual machine, because Python is a lot of Linux The core components of the release version, any accident can damage your system.

The following steps are based on Red Hat versions such as CentOS(6 and 7), Debian -based versions such as Ubuntumint and the Resbian You can skip this step, Pythonn 3 It should already be installed by default. If not, Install the appropriate package using Apt-get instead of yum.

[[email protected]] Yum Groupinstall ' development Tools '

[[email protected]] Yum install-y zlib-dev openssl-devel sqlite-devel bzip2-devel

[[email protected]] wget https://www.python.org/ftp/python/3.4.2/Python-3.4.2.tgz

[[email protected]] TAR-XVZF python-3.4.2.tgz

[[email protected]] CD Python-3.4.2

[[email protected]]./configure

[[email protected]] make

# make altinstall is recommended to overwrite the current python library

[[email protected]] make Altinstall

After successful installation, you should be able to enter the Python3.4 Shell with the following command .

[[Email protected]]# python3.4

Python 3.4.2 (Default, Dec 12 2014, 08:01:15)

[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on Linux

Type "Help", "copyright", "credits" or "license" for more information.

>>> exit ()

Using pip to install packages

Python has its own package management, similar to yum and apt-get . You will need it to download, install, and uninstall the package.

[[email protected]] pip3.4 install "PackageName"

[[email protected]] pip3.4 list

[[email protected]] pip3.4 Uninstall "PackageName"

Python Virtual Environment

In Python , a virtual environment is a directory of dependent environments where your project is placed. This is a good way to isolate projects with different dependent environments. It allows you to install packages without the sudo command.

[[email protected]] mkdir Python3.4-flask

[[email protected]] CD Python3.4-flask

[[email protected] python3.4-flask] pyvenv-3.4 venv

To create a virtual environment you need to use the "pyvenv-3.4" command. The above command creates a directory called Lib inside the venv folder , where the packages that the project depends on are installed. A bin folder will also be created to accommodate pip and python executables in that environment .

Activating a virtual environment for our Linux System Information Project

[[email protected] python3.4-flask] source venv/bin/activate

[[email protected] python3.4-flask] which pip3.4

~/python3.4-flask/venv/bin/pip3.4

[[email protected] python3.4-flask] which python3.4

~/python3.4-flask/venv/bin/python3.4

installing flask with pip

Let's continue to install the first module Flask Framework, which can handle access to routes and render templates that display our app .

[Email protected] python3.4-flask]pip3.4 Install flask

This is the way to create your first app on Linux using Python and Flask , recommended for all learning The students of Python development! If you have any questions, please read the relevant articles to learn all kinds of knowledge of Python development. Welcome to Exchange and learn from each other ~

Related article: " 4 tools for code conversion between Python and JavaScript " (http:// www.maiziedu.com/group/article/13663/)

How to create an app on Linux using Python and flask

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.