Pipenv, the new Python packaging tool

image with python logo with pipenv text on a blue background


published on: | by cindy In category: Python

Clearly,I have been living under a rock but not anymore! I shared an article using pipi and M. Floering suggested I check pipenv. You guessed right , yes I did and I am loving it! Pipenv is the official recommended python packaging tool acccording to pipenv.org. It is a great tool for managing your project's dependencies as well as install and uninstall packages.

Seems like pip and virtualenv did just well, but why pipenv?

  1. Think of pipenv as a powerful combination of pip and virtualenv.
  2. Goodbye to manually creating and managing you virtual environments pipenv does it for you!.
  3. Great at managing project's dependencies.Instead of pip''''s requirements.txt, pipenv creates two files the pipfile for the packages you installed directly and pipfile.lock for the dependencies and the specific version of the packages based on your pipfile.

pipenv workfow

  1. Create virtualenv if doesn't exist already.
  2. Create pipfile to manage the packages installed by you
  3. Finally, creates pipfile.lock to manage dependencies for the packages in pipfile

Let's get started!

We use pip to install pipenv,so ensure you have both python and pip installed. To check if pip is installed run:

$ pip --version

.. and python:

$ python --version

Installing pipenv

$ pip install --user pipenv

Note: I have used the user installation otherwise just run $ pip install pipenv .

Using pipenv

Now that we have successfully installed pipenv, let's use it to create the project directory and name it(I will call mine laughing-blog) and then change directory into the project's folder. Let's Initiate pipenv by using the install command.

$ mkdir laughing-blog //projectname
$ cd laughing-blog
$ pipenv --three install

Note:Specify your python version by using $ pipenv --three for python 3 and $ pipenv --two for python 2.To use an abitrary python version do: pipenv --python 3.6.4 or just $ pipenv install to use the default python version.

The above code creates a new virtual environment for your project if it doesn’t exist already and the two magic files, Pipfile and Pipfile.lock in your project directory.

Below is a breakdown of the pipenv install output.


Creating a virtualenv for this project…
Using /usr/bin/python3 (3.5.2) to create virtualenv
Virtualenv location: /home/cindy/.local/share/virtualenvs/laughing-blog-FpALE3CM


Creating a Pipfile for this project…

Finally, pipfile.lock

Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Updated Pipfile.lock (711973)!
Installing dependencies from Pipfile.lock (711973)…
🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00

Activating Virtualenv

To activate virtualenv,simply run:

$ pipenv shell

To exit virtulalenv,run:

$ exit

Managing Packages

To install a package simply run:

$ pipenv  install <packagename>

... and to remove the package in the pipfile run:

$ pipenv  uninstall <packagename>

understanding pipfile and pipfile.lock


Pipfile manages the packages that you install,think of it as an upgrade of requirements.txt.

What makes pipfile superior to requirements.txt

Lets look at a sample of requirements.txt file

Note:simply run pip freeze > requirements.txt to generate the above file


You will notice that requirements.txt list all the package we installed , version and the dependencies as well. pipfile holds the packages we installed and spare the rest to pipfile.lock


This is the file that contains the dependencies based on the packages present in Pipfile, the specific version of the packages to be used, avoiding the risks of automatically upgrading packages that depend upon each other and breaking your project dependency tree. If pipfile.lock wasn't created for some reason, you can lock the currently installed packages by running:

$ pipenv lock

pipfile sample

 django = "*"
 django-allauth = "*"

 python_version = "3.5"

pipfile.lock sample

  "django-allauth": {
        "hashes": [
        "index": "pypi",
        "version": "==0.35.0"
    "idna": {
        "hashes": [
        "version": "==2.6"
    "oauthlib": {
        "hashes": [
        "version": "==2.0.7"
    "python3-openid": {
        "hashes": [
        "version": "==3.1.0"


Now,you know the definition,advantages and how pipenv functions.And the difference between the two magic files pipfile and pipfile.lock