How to install Pipenv and use it for package version management

Published : Feb 3, 2024

Why we need pipenv

We previously looked at the ability to manage various python versions. This is the main piece of software that we will be using to create our programs. You can think of python as the main builder on a building site. The builder has his brain, his hands, eyes etc. all of which allow him to build a house.

That builder won’t just use his hands though, he’ll deploy tools to make him faster and more efficient. That is where packages come in. These are mini bundles of software which allow us to be faster and more efficient. For example, instead of writing out all the code for web scraping stock price data from yahoo finance, we might use a package called yfinance which is a small bundle of code.

Now if you were to give an electric drill to a builder in the 19th century, he wouldn’t know what to do with it. Similarly, if you try to use a new package on an old version of python, it won’t be able to work. This is where ‘virtual environments’ come into play. In programming, we set up these environments to ensure all python versions and package versions are compatible. The environment will lock in a version of python and ensure the packages installed are compatible.

How to install pipenv

Installing pipenv is straightforward and can be done using pip, Python's package manager. Here are the steps to install pipenv:

Prerequisites

Ensure you have Python installed on your system.

pipenv

requires Python to run.

Make sure

pip

is installed and up to date. You can check your

pip

version and update it using the following commands:

Installation Steps

Install

pipenv

Using

pip

: Run the following command in your terminal or command prompt to install

pipenv

:

Verify Installation

: After installation, you can verify that

pipenv

is installed correctly by checking its version:

Add

pipenv

to Path (if necessary)

: If your system does not recognize the

pipenv

command after installation, you may need to add it to your system's PATH. The installation process usually takes care of this, but it can sometimes be necessary to do it manually, especially on Windows.

Using pipenv

To start using

pipenv

in a project, navigate to your project directory and run:

To install a package and add it to your

Pipfile

, use:

To activate the virtual environment, run:

Additional Information

pipenv

is commonly used in development environments. For production, the

Pipfile.lock

is used to install exact versions of dependencies to ensure consistency.

pipenv

is particularly helpful when working on multiple Python projects, as it manages separate virtual environments for each project.

Remember, the effectiveness of pipenv can depend on how Python and pip are set up on your system, so make sure those are configured correctly before installing pipenv.