Overwriting module with same version in Heroku - Python

Updated 2026-09-26: replaced the runtime.txt trick with pinning the commit.

I needed to install a newer version of a module from a github commit, but it had the same version number. Heroku just used the cached version of the module and didn’t overwrite it with the newer version.

Pinning the commit in requirements.txt fixes it. Heroku’s Python buildpack throws away its package cache whenever that file changes, so the next push reinstalls everything:

somepackage @ git+https://github.com/someuser/somepackage.git@<commit sha>

If requirements.txt isn’t changing, purge the build cache with the heroku-builds plugin and push again:

heroku plugins:install @heroku-cli/heroku-builds
heroku builds:cache:purge -a example-app
git commit --allow-empty -m "Purge build cache"
git push heroku main