Reputation: 1124
For my (Django) project on Heroku, I updated one of the dependencies in my requirements.txt file to a newer version, and now I want Heroku to upgrade the version installed. I tried:
heroku run "pip install -r requirements.txt --upgrade -E ."
Which spits the right output to the terminal, but apparently does not actually upgrade anything; when I run:
heroku run "pip freeze -E ."
All of the package versions are the same. I even tried removing the package and that didn't work either. How do I force an upgrade of a dependency in a Python project on Heroku?
Upvotes: 16
Views: 8756
Reputation: 940
If for some reason it is still not updating, one thing you might try is deleting the dependency, pushing to git heroku master, and then re-adding the dependency with the right version and pushing again.
Upvotes: 0
Reputation: 662
I wanted to submit my answer just in case someone faces the same.
Heroku doesn't upgrade packages that are already in the version (which makes sense), however it fails to upgrade a package when installing from source, even if it's a different commit.
The solution I found is to force update by using a post-compile hook with pip install --upgrade -r requirements.txt
. Because the rest of the packages are pinned, it only affects source packages.
Upvotes: 7
Reputation: 249
Quick update on this that there are now utils to accomplish this function.
https://github.com/heroku/heroku-repo
Install the plugin in your Heroku toolbelt
heroku plugins:install https://github.com/heroku/heroku-repo.git
Clear the Heroku cache for your app (effectively removing all packages installed by pip)
heroku repo:purge_cache -a <APPNAME>
from the docs: This will delete the contents of the build cache stored in the repository. This is done inside a run process on the application
Rebuild
You can now push as normal.
Currently pushing seems to be the only way to cause a rebuild, see Recompile Heroku slug without push or config change here on StackOverflow for more info.
Upvotes: 9
Reputation: 5979
You should be able to upgrade it locally then re-run pip freeze. Within your requirements.txt the ==versionhere should be the version that installs each time you push.
When you run heroku run, its run in an isolated dyno that it is upgraded on then destroyed. For the change to persist it must occur during git push to be compiled into your slug.
Upvotes: 18