AWS上のUbuntu(16.04.2 LTS)に、Flask環境を構築しました。
####pipでvirtualenvをインストール
$ pip install --user virtualenv
Collecting virtualenv
Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
100% |????????????????????????????????| 1.8MB 711kB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-15.1.0
$ which virtualenv
/home/ubuntu/.local/bin/virtualenv
####仮想環境構築
$ virtualenv flask
Using base prefix '/home/ubuntu/anaconda3'
New python executable in /home/ubuntu/flask/bin/python
Installing setuptools, pip, wheel...done.
####アクティベート
$ source ./flask/bin/activate
####Flaskをインストール
(flask) ubuntu@ip-XXX:~$ pip install flask
Collecting flask
Downloading Flask-0.12.2-py2.py3-none-any.whl (83kB)
100% |????????????????????????????????| 92kB 3.2MB/s
Collecting itsdangerous>=0.21 (from flask)
Downloading itsdangerous-0.24.tar.gz (46kB)
100% |????????????????????????????????| 51kB 5.1MB/s
Collecting Jinja2>=2.4 (from flask)
Downloading Jinja2-2.9.6-py2.py3-none-any.whl (340kB)
100% |????????????????????????????????| 348kB 3.9MB/s
Collecting click>=2.0 (from flask)
Downloading click-6.7-py2.py3-none-any.whl (71kB)
100% |????????????????????????????????| 71kB 5.7MB/s
Collecting Werkzeug>=0.7 (from flask)
Using cached Werkzeug-0.12.2-py2.py3-none-any.whl
Collecting MarkupSafe>=0.23 (from Jinja2>=2.4->flask)
Downloading MarkupSafe-1.0.tar.gz
Building wheels for collected packages: itsdangerous, MarkupSafe
Running setup.py bdist_wheel for itsdangerous ... done
Stored in directory: /home/ubuntu/.cache/pip/wheels/fc/a8/66/24d655233c757e178d45dea2de22a04c6d92766abfb741129a
Running setup.py bdist_wheel for MarkupSafe ... done
Stored in directory: /home/ubuntu/.cache/pip/wheels/88/a7/30/e39a54a87bcbe25308fa3ca64e8ddc75d9b3e5afa21ee32d57
Successfully built itsdangerous MarkupSafe
Installing collected packages: itsdangerous, MarkupSafe, Jinja2, click, Werkzeug, flask
Successfully installed Jinja2-2.9.6 MarkupSafe-1.0 Werkzeug-0.12.2 click-6.7 flask-0.12.2 itsdangerous-0.24
####hello.pyを作成
(flask) ubuntu@ip-XXX:~/flask/code$ vi hello.py
hello.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == '__main__':
app.run()
####実行
(flask) ubuntu@ip-XXX:~/flask/code$ python hello.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
####別のターミナルを立ち上げて、curlで確認
$ curl http://localhost:5000
Hello, World!