――I've run a simple Python script or a simple program on Google App Engine, but I've never run a web program on its own, so I'll try it.
――Since it is a copy and paste from various places, there may be extra work. --The environment is Mac (El Capitan). --The brew and pip commands were included before.
--It is a version switching environment for python. Python itself will be installed in the user directory.
% brew link autoconf pkg-config
% brew install pyenv
% brew install pyenv-virtualenv
--If writing under / usr / local / is prohibited, change the ownership etc.
--It seems to be a (?) Command that virtualizes the entire environment. --The virtualenv command seems to be only for python2 series, and it seems that 3 series is a different command, but for the time being, with virtualenv
% pip install virtualenv
--If you leave it as it is, it will use the system python, so change the environment variable to use pyenv's python. --Since I am zsh, I write it in .zshrc, but if it is standard, write it in .bash_profile.
% echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
% echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
% echo 'eval "$(pyenv init -)"' >> ~/.zshrc
--For the time being, try installing the versions 2.7.11 and 3.5.1.
% pyenv install 2.7.11
% pyenv install 3.5.1
--Confirmation of installation.
% pyenv versions [~]
* system (set by /Users/user/.python-version)
2.7.11
3.5.1
--According to the system setting, there are three explicit numbers, 2.7.11 and 3.5.1.
--First, create a program directory to run the system and move to it.
% cd /[path]/proj
--Here, create a virtual environment with the virtualenv command.
% virtualenv testapp
-/ [path] / proj / testapp <-This will be the program folder with a nice environment.
--Switch to the virtual environment in testapp. The shell also has (testapp), so you can see that it has switched.
% source testapp/bin/activate
(testapp) [user]%
--Enter Flask.
(testapp) [user]% pip install Flask
Collecting Flask
Using cached Flask-0.11.1-py2.py3-none-any.whl
Collecting click>=2.0 (from Flask)
Collecting Werkzeug>=0.7 (from Flask)
Using cached Werkzeug-0.11.10-py2.py3-none-any.whl
Collecting Jinja2>=2.4 (from Flask)
Using cached Jinja2-2.8-py2.py3-none-any.whl
Collecting itsdangerous>=0.21 (from Flask)
Collecting MarkupSafe (from Jinja2>=2.4->Flask)
Installing collected packages: click, Werkzeug, MarkupSafe, Jinja2, itsdangerous, Flask
Successfully installed Flask-0.11.1 Jinja2-2.8 MarkupSafe-0.23 Werkzeug-0.11.10 click-6.6 itsdangerous-0.24
(testapp) [user]% pip list
click (6.6)
Flask (0.11.1)
itsdangerous (0.24)
Jinja2 (2.8)
MarkupSafe (0.23)
pip (8.1.2)
setuptools (23.0.0)
Werkzeug (0.11.10)
wheel (0.29.0)
(testapp) [user]% tree -L 2
.
└── testapp
├── bin
├── include
├── lib
└── pip-selfcheck.json
4 directories, 1 file
hello.py
# coding: utf-8
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
@app.route('/ja')
def hello_world_ja():
return 'Hello World!'
if __name__ == '__main__':
app.run()
――I don't understand the rules yet, so I put it in app / hello.py like this.
(testapp) [user]% tree -L 3 [~/Desktop/python-dev/proj]
.
└── testapp
├── app
│ └── hello.py
├── bin
├── include
├── lib
└── pip-selfcheck.json
(testapp) [user]% python testapp/app/hello.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
――It seems that it worked on 5000 ports.
--You can use a browser, but open another terminal and check.
% curl http://localhost:5000
Hello World!
% curl http://localhost:5000/ja
Hello World!
――It worked ~