Python Package Management with Pipenv

I started developing web apps with PHP and Nodejs where we have composer and npm respectively to manager packages. Every time I return to program in python, I realize the need to set up a virtual enviroment to manage project dependencies. Luckly, we now have Pipenv to save us from this pain. 😀 Below I’ll show the basic flow for working with Pipenv.

Install Pipenv

Let’s start by isntalling pipenv. If you are a Python developer, you are probably familiar with pip. So install pipenv with the following

pip install pipenv

Hello World

Let’s now build a simple application using a library called numpy. Start by creating a new directory:

mkidr new-project
cd new-project

Now, let’s install numpy by using Pipenv

pipenv install numpy

This will create a virtual env for us, just for our new-project! That’s much easier than managing that ourselves 😀

Now let’s create a python file to test this out.


Inside that file add the following

import numpy as np
 a = np.array([1,2,3])
 print a

Now to run the program we use the following

pipenv run python

And that’s it! The run command is a little verbose, but it saves us a lot of time overall.

Let me know if you have any questions and happy coding!