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.

touch index.py

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 index.py

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!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s