0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS上のUbuntuでFlask環境を構築

Last updated at Posted at 2017-11-04

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!
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?