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.
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)
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:
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
Sea bream
Reference
Recommended Posts