Getting Started with Pipenv Managing Python Dependencies Efficiently
Coursera
- This is a API course is one part of the overall Meta Back-end Developer course
Pipenv
For the first time, I’m using
pipenv
as I’m accustomed to usingvirtualenv
andpip
So, I was curious about the differences between them and the benefits of using
pipenv
requirements.txt
and (Pipfile
,Pipfile.lock
) are all used to manage the dependencies of a Python project
Requirements.txt
pip install -r requirements.txt
First, install the packages, and then compare the hash value specificed in requirements.txt with the actual hash value of the package
If the hash does not match, the package installation is stopped and error message is displayed
SHA256
hash algorithm, generated when the package is installedKey point : Not abstract, specify the exact versions of dependencies
Pipfile
Pipfile
&Pipfile.lock
On the other hand, you can make abstract dependency declaration using
Pipfile
. you can delcare dependencies without specifying a certain versionThe
abstract dependency
refers to the way of requesting packages without specifying a specfic version. For example, when you need the requests package, but you don't need to specify which version you need.Pipfile.lock
interprets these abstract dependencies into specific versions and includes the hash of each packageTherefore, using
Pipfile
andPipfile.lock
allows you to manage dependencies more conveniently and securelyTeam Project
Usually, One person runs the
pipnev lock
command to create thePipfile.lock
and shares this file with all team members.
How to use pipfile
- Install pipenv
1
pip install pipenv
- Install package (for me, I installed django)
1
pipenv install django
This command creates
Pipfile
in your directory
Or, add package directly to the Pipfile
- Create text file
Pipfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[[source]] url = "https://pypi.org/simple" verify_ssl = true name = "pypi" [packages] django = "*" djangorestframework = "*" djangorestframework-xml = "*" djoser = "*" [dev-packages] [requires] python_version = "3.11"
In this case, I added django, DRF, djoser packages under the
[packages]
section. - Run Install
1
pipenv install
Once the installation is complete (create Pipfile or using
pipenv install
), Update thePipfile.lock
1
pipenv lock