1

I just started a new Django project and use Postgresql as my database, so I installed psycopg2 to make it work properly. When i deployed the project in the beginning the app did not work because psycopg2 was not installed on the production server. As i quickly realized this was because psycopg2 was missing in my pipfile.

So my question is:

Do I have to update the pipfile manually every time i install something for my project? I thought that the pipfile would take care of that automatically every time I install something.

Isn't there anything similar to pip freeze > requirements.txt where I can do the update with one short command?

Daniel
  • 963
  • 1
  • 12
  • 29
  • `requirements.txt` is not per se the (only) pipfile. It is just a file, there is no "magic" that gives `requirements.txt` a special meaning. You can however for example install a `git` hook that will automatically first update the `requirements.txt` before committing. – Willem Van Onsem Sep 28 '19 at 10:19
  • But still I have to manually edit my Pipfile if I understand you correctly? Actually I do not work with a requirements.txt since when I install django with pipenv, a Pipfile is created automatically showing all dependeciies...however as far as I understand this file is not automatically updated any time I install something after its creation. Am i correct? – Daniel Sep 28 '19 at 10:26
  • not per se, what is not working with `pip freeze > requirements.txt`? We can automate that process, to do that each time you make a commit. – Willem Van Onsem Sep 28 '19 at 10:34

1 Answers1

3

Do I have to update the pipfile manually every time i install something for my project? I thought that the pipfile would take care of that automatically every time I install something.

requirements.txt is just a file. There is no logic around it that updates that (unless of course you have an IDE that does that). It is not per se the file that is used for the package manager. You can use any file, and you can use multiple files (for example sometimes one makes a requirements_test.txt file that contains extra packages that should be installed when testing the software).

You do not per se need to update the requirements.txt file each time you install software, as long as the requirements.txt file is correct when you deploy software (on another machine), it is fine.

You can however automate this to some extent. If you use git subversioning for example, you can make a pre-commit hook, that will each time run when you commit changes. For example by constructing an executable file in .git/hooks/pre-commit in the repository. Something that might look like:

#!/bin/bash

. env/bin/activate
pip freeze > requirements.txt

Each time you thus make a commit, the requirements.txt will be "harmonized" with the packages installed in the virual environment.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555