Newer developers often install everything at the system level due to a lack of understanding of, or experience with, virtual environments. Python packages installed with pip are placed at the system level. Retrieving requirements this way for every project creates an unmanageable global Python environment on your machine. Virtual environments allow you to compartmentalize your software while keeping an inventory of dependencies.
Pipenv, a tool for environment and package management, allows developers to create isolated software products that are easier to deploy, build upon, and modify.
Pipenv combines package management and virtual environment control into one tool for installing, removing, tracking, and documenting your dependencies: and for creating, using, and managing your virtual environments. Pipenv is essentially pip and virtualenv wrapped together into a single product.
Heroku offers many software service products. We’ll need the Heroku cloud platform service to host an app and mLab to use a MongoDB database. Don’t worry, creating an account and using these features is free!
The cloud platform supports apps in many programming languages including, Python, Node.js, Scala, Ruby, Clojure, Java, PHP and Go. We are going to use the Heroku GUI to deploy a database and a Python app.
In our previous deployments, we used SQLite and JawsDB databases. When using an SQLite database, every app redeployment will reset your database. JawsDB is excellent for deploying a MySQL relational database that will persist through app updates. This time, we want a document-based database system, in the form of MongoDB’s mLab add-on in Heroku.
Heroku allows us to deploy an app from a GitHub branch. Once we have a working app with a Pipfile pushed to GitHub, be sure to have your Pipfile at the project’s root directory, we are ready to make some final changes to the repository to prepare for deployment.
Note: These changes allow our app to run on Unix systems. Gunicorn is not compatible with PCs, so you will not be able to test these changes locally.
Gunicorn is a Python WSGI HTTP server that will serve your Flask application on Heroku. By running the line below, you add gunicorn to your Pipfile.
#cloud-computing #towards-data-science #mongodb #python