Touch Flask + run with Heroku

Prepare Python

version uses the latest version of 2 series. Use pyenv for Python version control and virtualenv for directory-specific environment isolation. Since I am using a Mac, from brew,

brew install pyenv
brew install pyenv-virtualenv

Install with.

$ pyenv install -l | grep 2.7
  2.7
  2.7-dev
  2.7.1
  2.7.2
  2.7.3
  2.7.4
  2.7.5
  2.7.6
  2.7.7
  ironpython-2.7.4
  jython-2.7-beta1
  jython-2.7-beta2
  stackless-2.7-dev
  stackless-2.7.2
  stackless-2.7.3
  stackless-2.7.4
  stackless-2.7.5
  stackless-2.7.6

The latest version seems to be 2.7.7. Install it.

pyenv install 2.7.7

Since I used the old pyenv, the following error occurred. What to do if a checksum error occurs when inserting 2 systems with pyenv on Mac --Qiita Check by changing the version

$ pyenv shell 2.7.7
$ python --version
Python 2.7.7

OK.

Introduce Flask

First move to the development directory.

cd path/to/proj
virtualenv venv27

activate (don't forget source or .)

source venv27/bin/activate

Flask, gunicorn install

pip install Flask

Verification

$ pip list
Flask (0.10.1)
itsdangerous (0.24)
Jinja2 (2.7.3)
MarkupSafe (0.23)
pip (1.5.6)
setuptools (3.6)
Werkzeug (0.9.6)
wsgiref (0.1.2)

Develop

Hello World!

Create hello.py.

hello.py


from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    app.run()

Run locally.

$ python hello.py
 * Running on http://127.0.0.1:5000/

Displayed when accessing http://127.0.0.1:5000/: congratulations:

 2014-12-06 12.03.03.png

Run on Heroku

Insert gunicorn

pip install gunicorn

Verification

$ pip list
Flask (0.10.1)
gunicorn (19.1.1)
itsdangerous (0.24)
Jinja2 (2.7.3)
MarkupSafe (0.23)
pip (1.5.6)
setuptools (3.6)
Werkzeug (0.9.6)
wsgiref (0.1.2)

Prepare a Procfile

procfile · herokaijp/devcenter Wiki

web: gunicorn hello:app --log-file -

Export requirements.txt

pip freeze > requirements.txt

Make a .gitignore Exclude the virtualenv directory (venv27).

*.pyc
*.pyo
venv27

Commit to git and push.

git add .
git commit -m 'Hello World!'
git push origin master

Log in to heroku and push.

heroku login
heroku create
git push heroku master

Add an instance of the web

heroku scale web=1

open

heroku open

 2014-12-06 12.35.59.png

Sea bream

Reference

Recommended Posts

Touch Flask + run with Heroku
Run the app with Flask + Heroku
I tried linebot with flask (anaconda) + heroku
Easy web app with Python + Flask + Heroku
Getting Started with Heroku, Deploying Flask App
Launch Flask application with Docker on Heroku
How to upload with Heroku, Flask, Python, Git (4)
Create a bulletin board with Heroku, Flask, SQLAlchemy
Easily realize microservices with Cloud Run x Flask
Run Flask on CentOS with python3.4, Gunicorn + Nginx.
Run prepDE.py with python3
Run Blender with python
IP restrictions with Flask
Hello world with flask
Run Apache2 + WSGI + Flask
Programming with Python Flask
Run iperf with python
How to upload with Heroku, Flask, Python, Git (Part 3)
How to upload with Heroku, Flask, Python, Git (Part 1)
How to upload with Heroku, Flask, Python, Git (Part 2)
How to deploy a web app made with Flask to Heroku
Deploy Flask with ZEIT Now
Run python with PyCharm (Windows)
Hello World with Flask + Hamlish
Run Python with CloudFlash (arm926ej-s)
Let's run Excel with Python
Unit test flask with pytest
API with Flask + uWSGI + Nginx
SNS Flask (Ajax) made with Flask
Web application development with Flask
(Failure) Deploy a web app made with Flask on heroku
From environment construction to deployment for flask + Heroku with Docker
To run gym_torcs with ubutnu16
Run LINE Bot implemented in Python (Flask) "without using Heroku"
Run Label with tkinter [Python]
Create Heroku, Flask, Python, Nyanko bulletin boards with "csv files"
View flask coverage with pytest-cov
Run Apache-Spark with IPython Notebook
Web application with Python + Flask ② ③
File upload with Flask + jQuery
Run DHT22 with RasPi + Python
Web application with Python + Flask ④
Build a detonation velocity website with Cloud Run and Python (Flask)
Re: Life in Heroku starting from scratch with Flask ~ PhantomJS to Heroku ~
I made a Nyanko tweet form with Python, Flask and Heroku
SNS Flask (Model) edition made with Flask
Make Echolalia LINEbot with Python + heroku
SNS Python basics made with Flask
[Memo] Links for developing with Flask
Preparing to run Flask on EC2
Run Rotrics DexArm with python API
Creating a Flask server with Docker
Run mruby with Python or Blender
Persist Flask API server with forever
[Python] Use Basic/Digest authentication with Flask
Use Flask to run external files
Next, use Python (Flask) for Heroku!
How to run matplotlib on heroku
Run SwitchBot on Windows 10 with Bleak
Run XGBoost with Cloud Dataflow (Python)
Basic authentication and Digest authentication with Flask