Skip to main content

HOW TO DEPLOY A PYTHON SCRIPT OR PROJECT ON HEROKU

Cloud computing has been one of the biggest revolutions of our time. This has given birth to a lot of cloud services that help, developers and even common people, solve day to day problems. For example, google drive, dropbox etc. are cloud services that give us space to store our data on the cloud (server). Cloud computing has nothing to do with the actual clouds (if you don’t already know). A cloud is a reference to a remote server that we are given temporary access to for a particular kind of usage.

Heroku is on such service which allows users to use their server for hosting applications.  This is, provide a platform for running the source code of the project. This service is free, however, there is also a paid account with more privileges. It also allows users to host databases on it. It supports several languages. And it provides a log of all the activities of the project.
So let get to the part where we have to deploy python projects or scripts on heroku. Since python is also used for writing small scripts, services like heroku can be very handy and money saving. Simple scripts such as a web scraper, data collector, etc. can be easily hosted on heroku for free. Now, let’s just get into how to do it.

Requirements:
  • Heroku tool belt
  • A basic knowledge of using GIT on command line

If you don’t know what GIT is, please google it. Because it is very important to understand how GIT works, in order to deploy python stuff on heroku. Even otherwise, it is very helpful if you know GIT.
Download and install heroku toolbelt from toolbelt.heroku.com . Once you have that covered, it is just a few steps more.

After installing heroku toolbelt, make sure you are connected to the internet. Open command prompt or any console and type ‘heroku’. It will automatically download and install all the required dependencies. It will take several minutes. This is only for the first time. You don’t have to do this everytime you want to deploy.

Now go to www.heroku.com and sign up for a free account. Once you have done that, open the console in your project directory and type “heroku login”. It will ask you for your login credentials, enter them.

Then you will have to create a new project in heroku. You can do that by typing “heroku create project_name”. This will check if the given project is available or not. And if it is, it will create it.

Now you will have to create a proc file. This file will determine what kind of tasks the code will do. For example, weather it is a web app, or a bot, or anything else. This proc file can be made in any text editor. But it should not have the extension “.txt”. In fact, it should it should not have any extension. And the name of the file should be exactly “Procfile”. The contents of this file will depend on what kind of process your code will be doing. If it is a web app (flask), the process is ‘web’. And the Procfile should have the line “web:  gunicorn MainScriptName:app” in it. If the project is just a script doing tasks like web scraping, sending emails and stuff, the process is ‘bot’. And the Procfile should have the line “bot:  python MainScriptName.py”. I will not go any further into the contents of this file. It will be better if you google it and find out. Because this will depend on the exactly are the processes.

Also you will need to add a requirements.txt folder, which will contain all the required dependencies of the project. You can do this by simply executing the command “pip freeze > requirements.txt”. This automatically create a file called ‘requirements.txt’ in that directory. You can go through the file and manually remove the names of the dependencies that are not required for the project.
Now you will have to make a local GIT repository for your project. You can do this by executing these commands one by one in the same console: ‘git init’, ‘git add .’, ‘git commit –am “commitMessage”’. This will create a local GIT repository.

Now you have to push the local repository to heroku. This is fairly simple. Use the command ‘git push heroku master’. This will create a remote a repository of your project on a heroku server.
Now, go to the heroku website and login to your account. Go to your dashboard and there you can find your project. Inside your project, go to the resources tab and under the free dynos section, enable the process. This will start the execution of your source code.

Once you have started the project, you can view the log of your project in the setting menu on the top right.

So this is how you deploy a python script or a project on the heroku platform. I hope you found this helpful. If you have any suggestions or doubts, do mention it in the comment section.


Thank you.

Comments

Popular posts from this blog

HOW TO COPY ANY TEXT TO TURBO C++

Hello!!

Are you one of those people who is in the middle of a C++ program and you know what to do, but you don't know the syntax? So you google and find out the syntax. But in turbo c++ you cannot use ctrl+v. That might be a little pissing off. So the easiest solution would be to get rid of Turbo C++ and get a modern day compiler. But anyway, here is a post on how one can copy text from an external source into the turbo C++ environment.



Also see:Basic algorithms 101 : Checking for the validity of an email address (simple beginner approch) 
C++ is a very powerful language, but the Turbo C++ compiler is bloody ancient and very conservative. The Unix environment it has can be a pain in the neck sometimes. With the modern day compilers like C++ builder, eclipse, and stuff, programming in C++ has become so much easier. Unix environment is not really necessary to build an application. And these new compilers also have a lot of predefined functions for graphics, user interface etc.

Somet…

HOW TO GET SYMBIAN BELLE CUSTOM FIRMWARE FOR NOKIA 5800 xm

Nokia has a reputation for making very durable phones. Their built quality is good, the lifetime of the device is good, it has a perfect size for human hands etc. The battery life of the phone is also way better than many android phones. They last for 2-3 days when charged completely.

Adding to the physical features, the customer service is also good. Because of their durability the don't in fact need a customer care service. Even if they fall many times, they don't give up. They will still work. And that's the best part of Nokia.

Apart from all the good things, there are a lot of bad things as well. Like the UI. The UI of the Nokia phones are all the same. And they have stayed the same for years! Also when they come up with the new software they don't release it for all devices.




This is the only complaint a Nokia user will have. The phone is hard rock, but the UI and the firmware are stone age. All the user expects from the phone is that it looks cooler.

This post wil…

HOW TO EXTRACT ALL THE LINKS of A GIVEN WEBPAGE (with python)

Websites are made of web pages. Every webpage is made of html tags. And every webpage has a unique address called URL which stands for Uniform Resource Locator. Using which we can request the webpage html code from the server. Once we send the request, the server will give us the html file for the webpage and our browser translates the code into readable English. This is the process that takes place every time we browse the internet.
In today’s post, we will see how to do that without the browser and rather through python. And also we will see how to grab all the links present on a website. A link is another URL. There can be many uses of doing this. For example, a web crawler does this all the time. It goes through the html code of a website and copies the links. And it visits those individual links and looks for other links in that page too. This is how the Google indexes pages. It crawls the whole of the internet every day. Python is very easy, as is this process. So let’s get star…