Master Python Dependency Management with Pipenv: A Complete Guide

Discover how Pipenv streamlines Python package management by automatically creating virtual environments, handling Pipfile and Pipfile.lock, offering deterministic builds, simplifying .env integration, and providing powerful commands like install, uninstall, lock, and graph, with step-by-step installation instructions for Windows and macOS.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Python Dependency Management with Pipenv: A Complete Guide

Pipenv – the officially recommended Python package management tool.

Pipenv combines the best features of various package managers (bundler, composer, npm, cargo, yarn) for Python, supporting all platforms.

It automatically creates and manages virtual environments, updates Pipfile when packages are installed or removed, and generates a Pipfile.lock to ensure deterministic builds.

Problems Pipenv Solves

You no longer need to use pip and virtualenv separately; Pipenv integrates them.

It replaces the problematic requirements.txt with Pipfile and Pipfile.lock for better reliability.

Security hashes are used throughout, automatically exposing vulnerabilities.

Provides a dependency graph via pipenv graph.

Loads environment variables from a .env file to simplify development.

Installation

Windows: pip install pipenv macOS (Homebrew):

brew install pipenv

Key Features

Deterministic builds with easy specification of desired packages.

Hashes are generated and verified when locking dependencies.

Automatically installs required Python versions if pyenv is available.

Recursively discovers projects by locating a Pipfile.

Creates a Pipfile automatically if missing.

Creates a virtual environment in the standard location.

Updates Pipfile automatically when packages are added or removed.

Loads a .env file automatically if present.

Basic Commands

pipenv install

– install packages (or all specified when no arguments). pipenv uninstall – remove packages. pipenv lock – generate Pipfile.lock. pipenv shell – spawn a shell with the virtual environment activated.

Concepts

A virtual environment is created automatically if it does not exist.

Running pipenv install without arguments installs all packages listed. pipenv --three creates a Python 3 environment; pipenv --two creates a Python 2 environment.

Other commands generate virtual environments with default settings.

Additional Commands

pipenv shell

– launches a shell with the virtual environment active. pipenv run – runs a command inside the virtual environment (e.g., pipenv run python). pipenv check – verifies that the environment satisfies PEP 508 requirements. pipenv graph – outputs a visual graph of installed dependencies.

Shell Completion

For fish shell, add the following to ~/.config/fish/completions/pipenv.fish:

eval (pipenv --completion)

For bash, add to .bashrc or .bash_profile:

eval "$(pipenv --completion)"

Application

Project location:

Virtual environment location:

Python interpreter location:

Package installation:

Install a development dependency:

Show dependency graph:

Generate a lockfile:

Install all development dependencies:

Uninstall everything:

Use the shell:

Documentation

Official documentation is available at https://docs.pipenv.org/.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Pythondependency managementvirtual environmentpackage managementpipenv
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.