Install and create HelloWorld sample
1. Environment
.OS: Centos 7.x
.Framework: Flask
.Python 2.7
[root@localhost ~]# python -V
Python 2.7.5
1.1 Install Python
CentOS 7 is still defaulting to Python 2.7
1.2 Install pip
yum install epel-release
yum -y install python-devel
yum -y install python-pip
pip install pip –upgrade
Check pip version
[root@localhost src]# pip -V
pip 9.0.3 from /usr/lib/python2.7/site-packages (python 2.7)
1.3 Install virtualenv for development environment
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.
1.4 Install Flask framework
pip install Flask
2. Create a new project
mkdir HelloWorl
cd HelloWorl
virtualenv venv
Activate environment
[root@localhost HelloWorl]# chmod -Rf 755 venv/
[root@localhost HelloWorl]# venv/bin/activate
4. Create Hello World
4.1 Edit a file
vi helloworld.py
from flask import Flask
app = Flask(__name__)
@app.route(‘/’)
def hello_world():
return ‘Hello World!’
if __name__ == ‘__main__’:
app.run(host=’127.0.0.1′, port=5000, debug=True)
4.2 Runing test
python helloworld.py
A message in Python shell informs you that
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Open the above URL (localhost:5000) in the browser. ‘Hello World!’ message will be displayed on it.
Would you like to work with us in NeosCorp, please contact us here!
http://neoscorp.vn/vi/contact
You need to login in order to like this post: click here
YOU MIGHT ALSO LIKE