Skip Navigation
Show nav
Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
    • .NET
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
Hide categories

Categories

  • Heroku Architecture
    • Compute (Dynos)
      • Dyno Management
      • Dyno Concepts
      • Dyno Behavior
      • Dyno Reference
      • Dyno Troubleshooting
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Developer Tools
    • Command Line
    • Heroku VS Code Extension
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery & Integration (Heroku Flow)
    • Continuous Integration
  • Language Support
    • Node.js
      • Troubleshooting Node.js Apps
      • Working with Node.js
      • Node.js Behavior in Heroku
    • Ruby
      • Rails Support
      • Working with Bundler
      • Working with Ruby
      • Ruby Behavior in Heroku
      • Troubleshooting Ruby Apps
    • Python
      • Working with Python
      • Background Jobs in Python
      • Python Behavior in Heroku
      • Working with Django
    • Java
      • Java Behavior in Heroku
      • Working with Java
      • Working with Maven
      • Working with Spring Boot
      • Troubleshooting Java Apps
    • PHP
      • Working with PHP
      • PHP Behavior in Heroku
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
    • .NET
      • Working with .NET
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
      • Migrating to Heroku Postgres
    • Heroku Key-Value Store
    • Apache Kafka on Heroku
    • Other Data Stores
  • AI
    • Working with AI
    • Heroku Inference
      • Inference API
      • Quick Start Guides
      • Inference Essentials
      • AI Models
    • Vector Database
    • Model Context Protocol
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
      • Single Sign-on (SSO)
    • Private Spaces
      • Infrastructure Networking
    • Compliance
  • Heroku Enterprise
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Language Support
  • Python
  • Python Behavior in Heroku
  • Python Dependencies via pip

Python Dependencies via pip

English — 日本語に切り替える

Last updated December 02, 2024

Table of Contents

  • The basics
  • Best practices
  • Git-backed distributions
  • Remote file-backed distributions
  • Local file-backed distributions
  • Private indexes
  • Cascading requirements files

This guide outlines how to fully utilize Heroku’s support for specifying dependencies for your Python application via pip.

Heroku’s pip support is very transparent. Any requirements that install locally with the following command will behave as expected on Heroku:

$ pip install -r requirements.txt

The basics

To specify Python package dependencies on Heroku via pip, add a pip requirements file named requirements.txt to the root of your repository.

Example requirements.txt:

Django==4.1.7
gunicorn==20.1.0

Best practices

If you follow these simple recommendations, your application builds will be deterministic:

  • All package versions should be explicitly specified.
  • All secondary dependencies should be explicitly specified.

This will ensure consistent build behavior when newer package versions are released.

Git-backed distributions

Anything that works with a standard pip requirements file will work as expected on Heroku.

Thanks to pip’s Git support, you can install a Python package that is hosted on a remote Git repository.

For example:

git+https://github.com/certifi/python-certifi

If your package is hosted in a private Git repository, you can use HTTP Basic Authentication:

git+https://user:password@github.com/nsa/secret.git

You can also specify any Git reference (e.g. branch, tag, or commit) by appending an @ to your URL:

git+https://github.com/certifi/python-certifi@develop

Optionally, you can install a dependency in “editable” mode, which will link to a full clone of the repository. This is recommended for Git-backed distributions that rely on upstream changes, as well as larger repositories.

The egg fragment is only valid with editable requirements.

-e git+https://github.com/django/django.git#egg=django

Remote file-backed distributions

You can also install packages from remote archives.

For example:

https://site.org/files/package.zip

This can be useful in many situations. For example, you can utilize GitHub’s tarball generation for repositories with large histories:

https://github.com/django/django/tarball/master

Local file-backed distributions

pip can also install a dependency from your local codebase. This is useful with making custom tweaks to an existing package.

You can use Git Submodules to maintain separate repositories for your File-backed dependencies. Git modules will automatically be resolved when you push your code to Heroku.

To add a local dependency in requirements.txt, specify the relative path to the directory containing setup.py:

./path/to/distribution

If you make changes to the library without bumping the required version number, however, the changes will not be updated at runtime. You can get around this by installing the package in editable mode:

-e ./path/to/distribution

Private indexes

To point to a custom package repository index, you can add the following to the top of your requirements file:

-i https://my-index.example.tld/mypath/

All dependencies specified in that requirements file will resolve against that index.

Cascading requirements files

If you would like to utilize multiple requirements files in your codebase, you can include the contents of another requirements file with pip:

-r ./path/to/prod-requirements.txt

We do not recommend this approach, but it is available to you.

Keep reading

  • Python Behavior in Heroku

Feedback

Log in to submit feedback.

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure
  • .NET

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing
  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Github
  • LinkedIn
  • © 2025 Salesforce, Inc. All rights reserved. Various trademarks held by their respective owners. Salesforce Tower, 415 Mission Street, 3rd Floor, San Francisco, CA 94105, United States
  • heroku.com
  • Legal
  • Terms of Service
  • Privacy Information
  • Responsible Disclosure
  • Trust
  • Contact
  • Cookie Preferences
  • Your Privacy Choices