Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize pip's requirements.txt in Heroku on deployment?

Tags:

python

pip

heroku

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?

like image 669
John Lehmann Avatar asked Jun 01 '13 20:06

John Lehmann


People also ask

Can I put pip in requirements txt?

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.

Do you need a requirements txt for Heroku?

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.

What goes in requirements txt Heroku?

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.


1 Answers

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.

like image 170
yellottyellott Avatar answered Oct 13 '22 06:10

yellottyellott