Publish an application using bottle on Heroku.
I made a web application with a Python bottle and tried to deploy it using Heroku, but it didn't work so I'll write an article as an output. Since this is my first post and I am a beginner, I would appreciate it if you could point out various things.
-Making a web application (echolalia) using Heroku and python web framework bottle [for beginners] -Publish your web app in 4 minutes 33 seconds using Heroku x bottle
Basically, I think that there is no problem with the procedure of these sites, but I have a bug, so I hope you can refer to it at that time.
You can create an account here (https://signup.heroku.com/).
Install the Heroku CLI from here (https://devcenter.heroku.com/articles/heroku-cli).
I was on Windows, so I ran heroku-x64.exe
after downloading the installer. I left the defaults for everything I chose.
Please make it. Note that it works in a remote environment. When running in a remote environment, I used the following code,
run(host="localhost",port=8080,debug=True)
When deploying, I changed it to the following code. I'm not sure what I'm doing around here, so I just copied the sutras for the time being.
run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)))
There is nothing special about main.py and other files. ** Caution </ font> ** ** Pay attention to the character code of requirement.txt, Procfile, runtime.txt. I couldn't deploy with the character code utf-16 LE, but I could deploy with utf-8. ** **
requirement.txt
This is a file that describes the module you want to import and its version. There seems to be a package when using numpy etc., but I stopped because I could not fix the error.
The contents are as follows.
The notation is module name == version
.
requirement.txt
bottle==0.12.18
numpy==1.18.5
scikit-learn==0.23.1
Procfile
I think this is a file that describes the python file to run (I don't understand much). I also created a file called Procfile.windows and wrote it as follows.
Rename the main.py
part below to your Python file. If you are using flask instead of bottle, it doesn't seem to be written as follows.
Procfile
web: python main.py
Procfile.windows
web: python main.py runserver 0.0.0.0:5000
runtime.txt
This is the version of Python to run. It seems that the supported version of Heroku has been decided, so I chose Python-3.8.5
for the time being. It was different from my execution environment, but it was cool (probably not good).
** Please note that you will get an error if you make a mistake in case. ** **
runtime.txt
python-3.8.5
** Pay attention to the character code of requirement.txt, Procfile, runtime.txt. I couldn't deploy with the character code utf-16 LE, but I could deploy with utf-8. ** **
Navigate to the directory you want to deploy and commit that directory.
cd (Directory you want to deploy)
git init
git add --all
git commit -m "first commit"
It's finally time to deploy to Heroku. ~~ I took more time here than creating an app ~~
First, log in to Heroku. You will be asked for the email address and password you registered with Heroku, so enter them.
heroku login
If all goes well, you should see something like this:
Logged in as my email address
Then do the following: This is creating an app on Heroku. If you do heroku create
, it will tell you the address, but that address will be the address of the web application. In this case, the name is set appropriately, but it seems that you can set it yourself.
heroku create
Finally, push.
git push heroku master
If all goes well, you should see code similar to the following.
remote: Verifying deploy... done.
On the contrary, if it doesn't work, the following code will be displayed.
error: failed to push some refs to 'https://git.heroku.com/XXXXXXX.git'
At this time, if you look closely at the top of the error code, it will tell you where it got stuck, but it is not so kind. So, if you go to the https://git.heroku.com/XXXXXXX.git
page, you can see the detailed log, so let's know more information there.
If you can deploy
heroku open
You can check the app at.
Recommended Posts