How to deploy the easiest python textbook pybot on Heroku

The easiest python textbook

[https://www.amazon.co.jp/ The easiest Python textbook-From the basics taught by popular teachers to server-side development-"The easiest textbook" series-Takanori Suzuki](https://www.amazon. co.jp/ The easiest Python textbook-From the basics taught by popular instructors to server-side development- "The easiest textbook" series-Takanori Suzuki / dp / 4295002089)

In addition to progate, I read this textbook when studying Python. Implementation of Pybot to the local environment is completed relatively smoothly. (Of course impressed)

If so, I want to actually deploy it on the Web! I will leave a record of trial and error here.

The first reference was this page

How to deploy pybot, the easiest python textbook

Already, it is as it is. Not in the title, but this one too (Heroku). This is as it is, but I will leave the deployment method that I did.

1. Environment construction

It remains common. 1 git 2 Python3 3 Heroku toolbelt → 3 User registration is required for Heroku. Please refer to other articles for details. 4

First, select the folder containing the pybotweb set with "cd (folder name)" in the command prompt, and create and activate the virtual environment.

python


C:\ Users \ (user name) \ (folder name)
python -m venv env
env¥Scripts¥activate.bat
#\ Is uppercase here, but lowercase

Upgrade pip to the latest version

python


python -m pip install --upgrade pip

Installation of each package

python


pip install requests
pip install bottle
pip install wikipedia

Make a note of the version of each package for later use.

2. Code creation

It is necessary to slightly rewrite Pybotweb.py created in the textbook. I used the sample code I used during trial and error.

pybotweb.py


 import os  #Added to the first line
  #run(host='localhost', port=8080, debug=True)  //Comment this out
  run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000))) #← Added to the last line

Creating a Procfile. It is possible on the command prompt. By the way, no extension is required.

python


echo web: python pybotweb.py > Procfile

Create requirements.txt. It is possible on the command prompt. By the way, the extension is .txt

python


pip freeze > requirements.txt

Creating runtime.txt. Let's check the version of python3. You can find it with "python --version". By the way, it doesn't have to be. I made it for the time being.

python


echo python-3.8.1(Enter version) > runtime.txt

3. Deploy on Heroku

Login and create apps. By the way, there are up to 5 free apps. I get an error when I try to make the 6th one.

python


heroku login
heroku create

Creating an initial git file

python


git init

Creating a remote repository

python


heroku git:clone -a (The app name given when you created heroku)
git add .

This is where I got stuck. I think that pybotweb has not only "pybotweb.py" but also other txt files. I had to add them all to git.

python


git add (pybotweb.All files except py)

From there, it's OK in the usual way.

python


git commit -m "initial commit"
git push heroku master

After clearing here, finally deploy.

python


heroku open

later https://qiita.com/sr2460/items/9f65474a63cfb0a2e407 It is as follows. Your pybot is on the web server! Impressive.

Next, we will aim for Linebot.

Recommended Posts

How to deploy the easiest python textbook pybot on Heroku
Think about how to program Python on the iPad
How to enjoy Python on Android !! Programming on the go !!
[Hyperledger Iroha] Notes on how to use the Python SDK
Don't lose to Ruby! How to run Python (Django) on Heroku
How to deploy django-compressor on Windows
How to get the Python version
How to run matplotlib on heroku
[Python] How to import the library
Deploy the Flask app on Heroku
Deploy the Flask app on heroku
How to deploy a Django app on heroku in just 5 minutes
[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 update the python version of Cloud Shell on GCP
How to read pydoc on python interpreter
[Kivy] How to install Kivy on Windows [Python]
Deploy the Django app on Heroku [Part 2]
Deploy the Django app on Heroku [Part 1]
How to erase Python 2.x on Mac.
Memorandum on how to use gremlin python
How to upload with Heroku, Flask, Python, Git (4)
[2020 version] How to install Python3 on AWS EC2
Strategy on how to monetize with Python Java
How to install OpenCV on Jetson Nano Python
[Python] How to change the date format (display format)
How to run MeCab on Ubuntu 18.04 LTS Python
The easiest way to use OpenCV with python
[Algorithm x Python] How to use the list
How to erase the characters output by Python
Introduction to Python with Atom (on the way)
How to get the files in the [Python] folder
[Python] How to install OpenCV on Anaconda [Windows]
[2015/11/19] How to register a service locally using the python SDK on naoqi os
[Python] How to save images on the Web at once with Beautiful Soup
How to install Python
How to install python
[Python] How to remove duplicate values from the list
How to retrieve the nth largest value in Python
How to get the variable name itself in python
How to put Takoyaki Oishikunaru on the segment tree
How to get the number of digits in Python
How to embed mod_wsgi into Apache on Python Windows
[Introduction to Python] How to iterate with the range function?
How to know the current directory in Python in Blender
How to deploy a Django application on Alibaba Cloud
[Reintroduction to python] How to import via the parent directory
Steps to install the latest Python on your Mac
How to upload with Heroku, Flask, Python, Git (Part 3)
How to use the Raspberry Pi relay module Python
[Python] How to specify the download location with youtube-dl
I tried python on heroku for the first time
How to build a Django (python) environment on docker
[Python] How to use the graph creation library Altair
How to upload with Heroku, Flask, Python, Git (Part 1)
How to upload with Heroku, Flask, Python, Git (Part 2)
[Introduction to Udemy Python3 + Application] 27. How to use the dictionary
[Introduction to Udemy Python3 + Application] 30. How to use the set
[Python] Summary of how to specify the color of the figure
How to use Django on Google App Engine / Python
How to use the model learned in Lobe in Python