[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.
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.
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
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