[Python + heroku] From the state without Python to displaying something on heroku (Part 1)

What is this?

Introductory article on heroku I often see ruby or node.js on OSX. Not so.

--In Python --On Win7 --I have an account registered on heroku -(I'm not good friends with git yet)

Let's start from such a place. As a goal, I don't go to apps or anything like that. Until something is displayed.

heroku official Python introductory documentation https://devcenter.heroku.com/articles/getting-started-with-python It is also an experience memo of (however, I eat only the parts that I think I need).


Installation

Python installation

Download it from here and install it.

https://www.python.org/downloads/

heroku02.png

Here, I put 2.7.11 which was the latest in 2 series at this time. (For CG, I think it's better to match the version with Python in the main tool. Here, I rushed without thinking about it. Then I thought later that I would put in 3 series)

Pass through PATH

Add it to the Windows environment variable PATH.

C:\Python27;C:\Python27\Scripts;

Actually, this time, I forgot to do this halfway and made it normal (?) From the middle. So, halfway through, it may include errors that didn't occur when you first did this. It may not be included.

If you want to add it with a command, it's setx

python


> setx /?

There are three ways to use SetX:

Syntax 1:
    SETX [/S system[/U [domain\]user[/P [password]]]]Variable value[/M]

Syntax 2:
    SETX [/S system[/U [domain\]user[/P [password]]]]
variable/K registry path[/M]

Syntax 3:
    SETX [/S system[/U [domain\]user[/P [password]]]]
         /F file{variable{/A x,y | /R x,y string}[/M] | /X} [/D delimiter]

Description:
Create environment variables or create environment variables in the user or system environment
change. Arguments, registry keys, or file input
You can set variables based on it.
(Omission)

virtualenv You said that you need virtualenv, so I'll put it in.

python


Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> import pip
>>> pip.main(["list"])
pip (7.1.2)
setuptools (18.2)
0

>>> pip.main(["install","virtualenv"])
Collecting virtualenv
  Downloading virtualenv-13.1.2-py2.py3-none-any.whl (1.7MB)
    100% |################################| 1.7MB 271kB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-13.1.2
0
>>>

You can usually use pip install virtualenv, but Here via Python's pip module.

heroku installation

There is an installer called ** heroku Toolbelt ** that will put in heroku and a set of tools related to it.

https://toolbelt.heroku.com/

The contents are git and ruby. heroku01.png

↓ It will be installed in this location and added to your PATH.

Technical details

The heroku client will be installed into C:\Program Files\Heroku and will be added to your %PATH%.

At the time of installation, did you wait for a while at the last git? It will be, but you don't have to be afraid.

git At this point, git is also included. I will check it. With emotional problems.

git -h.

git-h


C:\Users\{user}>git -h
Unknown option: -h
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

HM.

getting-started Follow this procedure below.

https://devcenter.heroku.com/articles/getting-started-with-python

heroku Immediately after installing Toolbelt "Once installed, you can use it with the heroku command! " It says something like Anyway, I saw it and executed it innocently with heroku. Did.

Then something like initialization ran, I've been waiting for a while because of add dependencies or something. let's wait. I was upset because I thought I had done something wrong. I don't have to wait a minute. Every time I wait in an unexpected place, I get scared. Because of a small person

By the way, in the log at this time, the window closed automatically after the initialization was completed. There is none (Because it was opened with win key> heroku)

Log on

heroku login You will then be asked for your heroku account email address and password.

python


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\{user}>heroku login
Enter your Heroku credentials.
Email: [email protected]
Password (typing will be hidden):
Logged in as [email protected]

Yes. It looks like.

Version confirmation

heroku version

python


C:\Users\{user}>heroku version
heroku/toolbelt/3.42.29 (i386-mingw32) ruby/2.1.7
heroku-cli/4.27.13-9dddf39 (386-windows) go1.5.3
=== Installed Plugins
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

I'm proceeding while reading this (▼)

http://developers.mobage.jp/blog/how-to-use-for-beginners-heroku

It is the content written in [2] there.

Test application location preparation

Create a folder that you want to use as the workshop this time and move it.

python


C:\Users\{user}>cd C:\Users\{user}\Documents\path\to\heroku_proj

C:\Users\{user}\Documents\path\to\heroku_proj>mkdir testapp

C:\Users\{user}\Documents\path\to\heroku_proj>cd testapp

C:\Users\{user}\Documents\path\to\heroku_proj\testapp>

Get a python sample for heroku

You will get ** python-getting-started ** published on github. git clone https://github.com/heroku/python-getting-started.git

python


C:\Users\{user}\Documents\path\to\heroku_proj\testapp>git clone https://github.com/heroku/python-getting-started.git
Cloning into 'python-getting-started'...
remote: Counting objects: 204, done.
emote: Total 204 (delta 0), reused 0 (delta 0), pack-reused 204Receiving objects
Receiving objects:  75% (153/204)
Receiving objects: 100% (204/204), 32.17 KiB | 0 bytes/s, done.
Resolving deltas: 100% (91/91), done.
Checking connectivity... done.

Then move with cd

python


C:\Users\{user}\Documents\path\to\heroku_proj\testapp>cd python-getting-started

C:\Users\{user}\Documents\path\to\heroku_proj\testapp\python-getting-started>

From now on, please understand that all commands are executed from C: \ Users \ {user} \ Documents \ path \ to \ heroku_proj \ testapp \ python-getting-started>.

Create heroku app

Imakoko

https://devcenter.heroku.com/articles/getting-started-with-python#deploy-the-app

heroku create.

python


>heroku create

Creating app... done, stack is cedar-14
https://ancient-taiga-0000.herokuapp.com/ | https://git.heroku.com/ancient-taiga-0000.git

** What is ancient-taiga-0000? ** ** Is it a sudden kitchen term? I think that, if you do not decide the name when creating, it seems that ** it will automatically name it **. Is it okay because it's a test?

If you name it properly heroku create your-app-name in this way. Or you can log in to heroku via a browser and change from there (not done)

Deploy

Here is a sudden git experience.

git push heroku master

It takes about 1-2 minutes.

python


>git push heroku master
Counting objects: 204, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (98/98), done.
Writing objects: 100% (204/204), 32.16 KiB | 0 bytes/s, done.
Total 204 (delta 91), reused 204 (delta 91)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing runtime (python-2.7.11)
remote: -----> Installing dependencies with pip
remote:        Collecting dj-database-url==0.3.0 (from -r requirements.txt (line 1))
remote:        Downloading dj_database_url-0.3.0-py2.py3-none-any.whl
remote:        Collecting Django==1.9.1 (from -r requirements.txt (line 2))
remote:        Downloading Django-1.9.1-py2.py3-none-any.whl (6.6MB)
remote:        Collecting gunicorn==19.4.5 (from -r requirements.txt (line 3))
remote:        Downloading gunicorn-19.4.5-py2.py3-none-any.whl (112kB)
remote:        Collecting psycopg2==2.6.1 (from -r requirements.txt (line 4))
remote:        Downloading psycopg2-2.6.1.tar.gz (371kB)
remote:        Collecting whitenoise==2.0.6 (from -r requirements.txt (line 5))
remote:        Downloading whitenoise-2.0.6-py2.py3-none-any.whl
remote:        Installing collected packages: dj-database-url, Django, gunicorn, psycopg2, whitenoise
remote:        Running setup.py install for psycopg2
remote:        Successfully installed Django-1.9.1 dj-database-url-0.3.0 gunicorn-19.4.5 psycopg2-2.6.1 whitenoise-2.0.6
remote:
remote: -----> Preparing static assets
remote:        Running collectstatic...
remote:        Post-processed 'admin/js/vendor/xregexp/LICENSE-XREGEXP.txt' as 'admin/js/vendor/xregexp/LICENSE-XREGEXP.d64cecf4f157.txt'
(Omitted)
remote:        Post-processed 'lang-logo.png' as 'lang-logo.019c8743b7cf.png'
remote:        58 static files copied to '/app/staticfiles', 58 post-processed.
remote:
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing... done, 42.1MB
remote: -----> Launching...
remote:        Released v4
remote:        https://ancient-taiga-0000.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy.... done.
To https://git.heroku.com/ancient-taiga-0000.git
 * [new branch]      master -> master

>

** requirements.txt ** is placed in python-getting-started, During the above process, it is read and installed with pip.

Then, heroku ps: scale web = 1.

python


>heroku ps:scale web=1
Scaling dynos... done, now running web at 1:Free.

from heroku open

python


>heroku open
Opening ancient-taiga-0000... done

Then, the browser will be launched and the app (here * ancient-taiga-0000.herokuapp.com *) will be opened.

Hmm.


So far

--Preparation --Make heroku app --Deploy and run on heroku

I was able to experience ...


View log

Imakoko

https://devcenter.heroku.com/articles/getting-started-with-python#view-logs

heroku logs --tail

If you add --tail, logs will be acquired more and more in real time. When you stop, Ctl + C

python


>heroku logs --tail
2016-01-17T13:37:24.947150+00:00 heroku[api]: Enable Logplex by [email protected]
2016-01-17T13:37:24.947150+00:00 heroku[api]: Release v2 created by [email protected]
2016-01-17T13:40:12.180138+00:00 heroku[api]: Attach DATABASE resource by [email protected]
2016-01-17T13:40:12.180177+00:00 heroku[api]: Release v3 created by [email protected]
2016-01-17T13:40:12.470201+00:00 heroku[api]: Scale to web=1 by [email protected]
2016-01-17T13:40:12.529336+00:00 heroku[api]: Deploy fe7f948 by [email protected]
2016-01-17T13:40:12.529336+00:00 heroku[api]: Release v4 created by [email protected]
2016-01-17T13:40:12.842955+00:00 heroku[slug-compiler]: Slug compilation started
2016-01-17T13:40:12.842964+00:00 heroku[slug-compiler]: Slug compilation finished
2016-01-17T13:40:15.096972+00:00 heroku[web.1]: Starting process with command `gunicorn gettingstarted.wsgi --log-file -`
2016-01-17T13:40:16.642246+00:00 app[web.1]: [2016-01-17 13:40:16 +0000] [3] [INFO] Listening at: http://0.0.0.0:10178 (3)
2016-01-17T13:40:16.642313+00:00 app[web.1]: [2016-01-17 13:40:16 +0000] [3] [INFO] Using worker: sync
2016-01-17T13:40:16.640646+00:00 app[web.1]: [2016-01-17 13:40:16 +0000] [3] [INFO] Starting gunicorn 19.4.5
2016-01-17T13:40:16.645613+00:00 app[web.1]: [2016-01-17 13:40:16 +0000] [9] [INFO] Booting worker with pid: 9
2016-01-17T13:40:16.684880+00:00 app[web.1]: [2016-01-17 13:40:16 +0000] [10] [INFO] Booting worker with pid: 10
2016-01-17T13:40:17.171330+00:00 heroku[web.1]: State changed from starting to up
(ry
2016-01-17T13:45:25.167623+00:00 app[web.1]: Not Found: /favicon.ico

If you try to stop with ctl + c, you will see the following

python


 !    Command cancelled.
Do you want to end the batch job?(Y/N)? y

>

Procfile Imakoko

https://devcenter.heroku.com/articles/getting-started-with-python#define-a-procfile

It is placed directly under "getting-started-with-python" that has been git cloned. I would like to know about ** Procfile file **.

On github, this

https://github.com/heroku/python-getting-started/blob/master/Procfile

In the initial state, the contents are like this web: gunicorn gettingstarted.wsgi --log-file -

It seems that you write clock: ~~ when you want heroku to process it automatically. It's a file that writes such settings.

ps Imakoko

https://devcenter.heroku.com/articles/getting-started-with-python#scale-the-app

Try heroku ps.

python


>heroku ps
=== web (Free): gunicorn gettingstarted.wsgi --log-file -
web.1: up 2016/01/17 22:40:17 (~ 18m ago)

>

heroku run ~~

It seems that something can be done with heroku run ~~

python


>heroku run
 !    Usage: heroku run COMMAND
 !
 !    Example: heroku run bash

>

I need something after run. .. .. By the way, I haven't helped heroku since I started working on it, so I'll try it here.

python


>heroku -h
Usage: heroku COMMAND [--app APP] [command-specific-options]

Primary help topics, type "heroku help TOPIC" for more details:

  addons    #  manage add-on resources
  apps      #  manage apps (create, destroy)
  auth      #  authentication (login, logout)
  config    #  manage app config vars
  domains   #  manage domains
  logs      #  display logs for an app
  ps        #  manage dynos (dynos, workers)
  releases  #  manage app releases
  run       #  run one-off commands (console, rake)
  sharing   #  manage collaborators on an app

Additional topics:

  2fa          #  manage two-factor authentication settings
  buildpacks   #  manage the buildpack for an app
  certs        #  manage ssl endpoints for an app
  drains       #  display drains for an app
  features     #  manage optional features
  fork         #  clone an existing app
  git          #  manage local git repository for app
  help         #  list commands and display help
  keys         #  manage authentication keys
  labs         #  manage optional features
  local        #  run heroku app locally
  login        #  Login with your Heroku credentials.
  maintenance  #  manage maintenance mode for an app
  members      #  manage membership in organization accounts
  orgs         #  manage organization accounts
  pg           #  manage heroku-postgresql databases
  pgbackups    #  manage backups of heroku postgresql databases
  plugins      #  manage plugins to the heroku gem
  regions      #  list available regions
  spaces       #  manage heroku private spaces
  stack        #  manage the stack for an app
  status       #  Status of Heroku Platform
  twofactor    #  manage two-factor authentication settings
  update       #  update the heroku client
  version      #  display version

Check the information of the heroku app

List your apps heroku apps

>heroku apps
=== My Apps
ancient-taiga-0000

Of course, there is only one at present.

heroku apps:info

>heroku apps:info
=== ancient-taiga-0000
Addons:        heroku-postgresql:hobby-dev
Dynos:         web: 1
Git URL:       [email protected]:ancient-taiga-0000.git
Owner:         [email protected]
Region:        us
Repo Size:     36 kB
Slug Size:     42 MB
Stack:         cedar-14
Web URL:       https://ancient-taiga-0000.herokuapp.com/

You can check what add-on you are using and the URL for access. Speaking of which, ** Region is us **.

Plugin confirmation

heroku plugins

python


>heroku plugins
=== Installed Plugins
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

Add-on confirmation

heroku addons

>heroku addons

Add-on                                           Plan       Price
───────────────────────────────────────────────  ─────────  ──
───
heroku-postgresql (postgresql-dimensional-7392)  hobby-dev  free
 └─ as DATABASE

The table above shows add-ons and the attachments to the current app (ancient-taiga-0000) or other apps.

Open the add-on page

>heroku addons:open heroku-postgresql
Opening heroku-postgresql (postgresql-dimensional-7392) for ancient-taiga-0000... done

Then this was opened ↓

https://postgres.heroku.com/databases

[email protected] does not exist or cannot be accessed by this account 

Is that so.

add on and verify account

By the way, some add-ons will not install unless you verify your account. In short, please register your payment information (credit card) It seems that.

※reference: Create a Twitter ToDo service with Unfiltered + Heroku (Try using heroku Add-on, configuration file and Scalate) @ Meinoshi http://mao-instantlife.hatenablog.com/entry/20120310/1331388396

If you skip the payment information registration and try to add an add-on, you will get this attitude. verify.png

I knew it!

release information

heroku releases

>heroku releases
=== ancient-taiga-0000 Releases
v4  Deploy fe7f948            [email protected]  2016/01/17 22:40:12 (~ 2h ago)
v3  Attach DATABASE resource  [email protected]  2016/01/17 22:40:12 (~ 2h ago)
v2  Enable Logplex            [email protected]  2016/01/17 22:37:24 (~ 2h ago)
v1  Initial release           [email protected]  2016/01/17 22:37:24 (~ 2h ago)

View preferences

heroku config

>heroku config
=== ancient-taiga-0000 Config Vars
DATABASE_URL: postgres://abcdefghijklmn:GaEMJZBYWhqmI9xXOOudegwpxf@ec2-54-83-61-45.compute-1.amazonaws.com:5432/d7vc7kpol1v9vn

Next

It's been long, so once. ~~ If you can write the second half, I will paste the link ~~> I wrote the second half

http://qiita.com/it_ks/items/ca6c7f6e8fc89e49e46d

Recommended Posts

[Python + heroku] From the state without Python to displaying something on heroku (Part 1)
[Python + heroku] From the state without Python to displaying something on heroku (Part 2)
How to deploy the easiest python textbook pybot on Heroku
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
Introduction to Python Hands On Part 1
Update Python on Mac from 2 to 3
Deploy the Django app on Heroku [Part 2]
Deploy the Django app on Heroku [Part 1]
I made something with python that NOW LOADING moves from left to right on the terminal
Connecting from python to MySQL on CentOS 6.4
Do something regularly from heroku to Shotgun
[IBM Cloud] I tried to access the Db2 on Cloud table from Cloud Funtions (python)
[Python] How to remove duplicate values from the list
The wall of changing the Django service from Python 2.7 to Python 3
Think about how to program Python on the iPad
From the initial state of CentOS8 to running php python perl ruby with nginx
Changes from Python 3.0 to Python 3.5
Steps to install the latest Python on your Mac
How to upload with Heroku, Flask, Python, Git (Part 3)
I tried python on heroku for the first time
I wanted to use the Python library from MATLAB
Find the part that is 575 from Wikipedia in Python
I sent regular emails from sendgrid on heroku, on python
How to upload with Heroku, Flask, Python, Git (Part 1)
How to pass arguments when invoking python script from blender on the command line
How to upload with Heroku, Flask, Python, Git (Part 2)
How to enjoy Python on Android !! Programming on the go !!
"Cython" tutorial to make Python explosive: Pass a C ++ class object to a class object on the Python side. Part ①
How to know the number of GPUs from python ~ Notes on using multiprocessing with pytorch ~
How to run Python on Windows without polluting the environment as much as possible (Scoop edition)
[Part 4] Use Deep Learning to forecast the weather from weather images
[Part 1] Use Deep Learning to forecast the weather from weather images
[Part 3] Use Deep Learning to forecast the weather from weather images
[Hyperledger Iroha] Notes on how to use the Python SDK
Don't lose to Ruby! How to run Python (Django) on Heroku
[Part.2] Crawling with Python! Click the web page to move!
[Part 2] Use Deep Learning to forecast the weather from weather images
Save images on the web to Drive with Python (Colab)
Program to determine leap year from the Christian era [Python]
Go language to see and remember Part 8 Call GO language from Python
Pass OpenCV data from the original C ++ library to Python
Extract the value closest to a value from a Python list element
Post from Python to Slack
Cheating from PHP to Python
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Update python on Mac to 3.7-> 3.8
Switch from python2.7 to python3.6 (centos7)
Connect to sqlite from python
How to easily create an environment where python code runs on Jupyter without polluting the local environment
About the error I encountered when trying to use Adafruit_DHT from Python on a Raspberry Pi
The story that the version of python 3.7.7 was not adapted to Heroku
The record I was addicted to when putting MeCab on Heroku
How to rebuild python environment from pyenv on Mac environment (El Capitan)
[Python] Try to graph from the image of Ring Fit [OCR]
How to get followers and followers from python using the Mastodon API
Things to note when running Python on EC2 from AWS Lambda
Use python on Raspberry Pi 3 to illuminate the LED (Hello World)
Simple code to call a python program from Javascript on EC2
Installation from python, numpy, scipy sources without root privileges on Linux
Terminal association from the server side to Amazon SNS (python + boto3)
The road to installing Python and Flask on an offline PC