I'm deploying a Python Django app to Heroku, and I'd like to customize the requirements.txt file (by adding a git-backed dependency with password) only when I deploy to certain environments like Heroku. I'd love to set this in an environment variable or something, but I don't believe pip has any functionality like that. My idea was to use a hook that Heroku provides to place a script which would add to my requirements.txt before the dependencies are installed. Is that possible?
Use the pip install -r requirements. txt command to install all of the Python modules and packages listed in your requirements. txt file. This saves time and effort.
Create necessary project files These are 1) the Procfile and 2) the `requirements. txt` file. Both of these are required by Heroku to install all app dependencies and subsequently utilize Gunicorn to fire off our app in the cloud. First create the Procfile.
txt in the root directory is one way for Heroku to recognize your Python app. The requirements. txt file lists the app dependencies together. When an app is deployed, Heroku reads this file and installs the appropriate Python dependencies using the pip install -r command.
You can include a requirements file in another requirements file.
# requirements.txt
-r requirements/base.txt
# requirements/base.txt
django==1.6
# requirements/heroku.txt
-r requirements/base.txt
djpostgresurlthing==1.0.0
# requirements/dev.txt
-r requirements/base.txt
django-debug-toolbar
I typically keep a requirements.txt
file in the root of the project that just includes other requirements files(usually prod or a base) and make a requirements/
folder with environment specific stuff. So locally I'd pip install -r requirements/dev.txt
and on the server pip install -r requirements/prod.txt
.
For your case with heroku, you need the root requirements.txt to be for heroku. So you can just use that file to include your heroku requirements file.
# requirements.txt
-r requirements/heroku.txt
There's probably SOME way to tell heroku to use a different file. But this would be an easy way to get around it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With