Python - Getting Started with Pipenv


Managing packages in Python has been a tricky subject. Whenever you create a program, you typically need to import other libraries user's have made. The typical way to do this is using pip install someoneslibrary. This will install the library on your computer. Many problems can arise from this, but one example is the libraries are not very portable or localized to your program.

Say you install version 1 of somoneslibrary and you write a new program using version 2. Both programs will be forced to use the same version if you install using pip in the way I showed above. Let's take a look at how pipenv solves this problem and others.


The Hitchhickers guide has a great example how to install pipenv on many systems: . For our purposed, we will use pip. Run the following:

pip install --user pipenv

You should now have pipenv installed. Refer to the link above for platform specific instructions. Sometimes you will need to configure env variables for your system.

You can check to ensure pipenv is installed correctly by doing the following:

pipenv --version

You should see details on your pipenv install after.

Basic Usage

OKay, let's start by creating a simple python program.

mkdir myProgram
cd myProgram

Now, let's say we want to use the popular requests module for python. The package is localed here:

We can install this using the following:

pipenv install requests

This will create a Pipfile and Pipfile.lock file. With these files in our directory, anyone can come to our folder and use pipenv install to get all the packages we are using in our program. That makes our new package very portable.

Okay, now open and add the following code.

r = requests.get('', auth=('user', 'pass'))

To run our program, we use the following:

pipenv run python

And there you have it! We can now use pipenv to manage our application :D

Bonus: Using a Makefile

Now, you may notice that running our program takes many more arguments from the command line. To solve this, we can use the classic make program that comes on most operating systems.

To do this, create a file called Makefile and add the following:

    pipenv run python

Now, we can run our program using the following command.

make run

That is much easier. There is much more to do with make. Let me show you an example from a program I have written.

    pipenv run python

    pipenv run python runserver

Here, I have two helper tasks I can run. If you are interested in Make, there are many good books and you can check out the documentation here: