PIPENV – The Python’s Packaging Tool


Pipenv, the official Python-recommended resource for managing package dependencies, letting us install and uninstall Python packages. Pipenv helped to solve a few problems associated with the typical workflow using pip, virtualenv, and traditional requirements.txt, consolidating and simplifying the development process to a single command line tool.

Problems that PIPENV solves

The major issue with packaging in Python is the need of the pip library for package installation along with a library for creating a virtual environment, a library for managing virtual environments and the commands associated with those libraries, which is tiresome to manage. Pipenv comes with the package management and virtual environment support so that installing, uninstalling, tracking, and documenting the dependencies, creating, using and organizing the virtual environments can be done with a single tool. When you start a project with it, Pipenv will automatically create a virtual environment for that project if you are not using one already. Pipenv does this dependency management by abandoning the requirements.txt norm and uses a new document called a Pipfile. When you install a library with Pipenv, the pipfile is automatically updated with the details of that installation, including the version information and possibly the Git repository location, file path, and other information.

Pipenv makes it easier to manage complex interdependencies. The app might depend on a specific version of a library, and that library might depend on a specific version of another library, causing conflicting dependencies. Pipenv keeps track of the tree of the app’s interdependencies in a file called Pipfile.lock. The Pipfile.lock also verifies that the right versions of dependencies are used in production.

Pipenv indicates to other people who work on the project that it has a standardized way to install project dependencies and development and testing requirements. Using a workflow with pip and requirements files means that you may have one single requirements.txt file, or several requirements files for different environments. Multiple requirements files require extra context and precise documentation to help others to install the dependencies properly and work as expected, which has the potential to confuse colleagues and increase the maintenance burden. Using Pipenv, which gives the Pipfile, one can avoid these problems by managing dependencies for different environments.

Installing PIPENV

To install PIPENV, run the following command

pip install pipenv

To start using PIPENV in your project, run…

pipenv install project_name

An indicator of Pipenv creating a Pipfile for your project is shown.

You may also see some output from Pipenv saying it is creating a virtual environment for you if you are not using one already.

To generate a Pipfile.lock file, run:

pipenv lock

You can also run Python scripts with Pipenv with the following syntax.

pipenv run python script_name

To start a shell, run…

pipenv shell

If you would like to convert a project that currently uses a requirements.txt file to use Pipenv, you can use…

pipenv install requirements.txt

Using PIPENV makes the packaging in python easier, thus making your life easier.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top