Generating requirements.txt from Pipfile.lock

I have been using pipenv to help me manage my python virtual environments.

I also use Heroku for some of my sites…and Heroku relies on the requirements.txt file rather than Pipfile/Pipfile.lock that pipenv uses.

Here is an easy way to generate a requirements.txt file from a Pipfile.lock

jq -r '.default
| to_entries[]
| .key + .value.version' \
Pipfile.lock > requirements.txt

NOTE: You will need the program ‘jq‘ (like sed for JSON data) installed, which can be done via:

sudo apt install jq

I believe that I learned about this method inside the issues tracker for pipenv on GitHub.

Leave a Reply

Your email address will not be published.