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
pipenvas I’m accustomed to usingvirtualenvandpipSo, I was curious about the differences between them and the benefits of using
pipenvrequirements.txtand (Pipfile,Pipfile.lock) are all used to manage the dependencies of a Python project
Requirements.txt
pip install -r requirements.txtFirst, 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
SHA256hash algorithm, generated when the package is installedKey point : Not abstract, specify the exact versions of dependencies
Pipfile
Pipfile&Pipfile.lockOn the other hand, you can make abstract dependency declaration using
Pipfile. you can delcare dependencies without specifying a certain versionThe
abstract dependencyrefers 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.lockinterprets these abstract dependencies into specific versions and includes the hash of each packageTherefore, using
PipfileandPipfile.lockallows you to manage dependencies more conveniently and securelyTeam Project
Usually, One person runs the
pipnev lockcommand to create thePipfile.lockand 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 djangoThis command creates
Pipfilein your directory
Or, add package directly to the Pipfile
- Create text file
Pipfile1 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.lock1
pipenv lock