This is a small example of running your script with Heroku. You can run almost any python application with any dependencies.
-
Download or clone this repository
-
Register on Heroku
-
Download and install Heroku CLI
-
Download and install git
-
Copy your script or project to this repository's folder
-
Replace "script.py" with the path to your main executable file in
Procfile
. For details aboutProcfile
refer to the docs. If you need to run web application, you have to useweb
instead ofworker
. -
You may select your python version and runtime using
runtime.txt
. Read how on official heroku page. -
If you are using any not built-in modules, you must add them to your
requirements.txt
. To check which version of the module you have, runpip freeze
in the terminal. You will get lines with information about installed modules and their versions in the format likeMODULE_NAME==MODULE_VERSION
. Add lines with required modules and their versions to yourrequirements.txt
. Heroku will install modules from this file automatically.If you are using some kind of virtual environment, you can generate ready-to-use
requirements.txt
withpip freeze > requirements.txt
. -
Open terminal (or do it another way, but I will explain how to do it in the terminal on Ubuntu) and create a git repository.
-
Initiate git repository
git init
-
Create heroku application
heroku create
-
Add, commit and push your code into branch
master
of the remoteheroku
.git add . git commit -m "initial commit" git push heroku master
-
-
Specify the amount of worker that will run your application
heroku ps:scale worker=1
-
Now everything should be working. You can check your logs with this command
heroku logs --tail
-
You can open the URL where the script is deployed using the below command (if you are deploying web application)
heroku open
-
From now on you can use usual git commands (push, add, commit, etc.) to update your app. Every time you
push heroku master
your app gets redeployed with updated source code -
To stop your application scale down the amount of workers with like this
heroku ps:scale worker=0
- @michaelkrukov - https://michaelkrukov.ru/