Pipenv: Python Development Workflow for Humans

What is Pipenv?

Image for: What is Pipenv?¶

Pipenv is a Python virtualenv management tool that combines pip, virtualenv, and Pipfile into a single unified interface. It creates and manages virtual environments for your projects automatically, while also maintaining a Pipfile for package requirements and a Pipfile.lock for deterministic builds.

Linux, macOS, and Windows are all first-class citizens in Pipenv.

Why Use Pipenv?

Image for: Why Use Pipenv?¶

Pipenv solves several critical problems in the Python development workflow:

  • Simplified Dependency Management: No need to use pip and virtualenv separately—they work together seamlessly.

  • Deterministic Builds: The Pipfile.lock ensures that the exact same environment can be reproduced across different systems.

  • Security First: Package hashes are documented in the lock file and verified during installation, preventing supply chain attacks.

  • Dependency Visibility: Easily visualize your dependency graph with pipenv graph.

  • Environment Isolation: Each project gets its own isolated virtual environment, preventing dependency conflicts.

  • Development Workflow Integration: Support for local customizations with .env files and development vs. production dependencies.

  • Latest Dependency Versions: Encourages the use of up-to-date dependencies to minimize security vulnerabilities.

Key Features

Image for: Key Features¶
  • Deterministic Builds: Generates and checks file hashes for locked dependencies.

  • Python Version Management: Automatically installs required Python version when pyenv or asdf is available.

  • Project-Centric Workflow: Automatically finds your project home by looking for a Pipfile.

  • Automatic Environment Creation: Creates a virtualenv in a standard location when one doesn’t exist.

  • Simplified Package Management: Automatically adds/removes packages to a Pipfile when they are installed or uninstalled.

  • Environment Variable Management: Automatically loads .env files to support customization and overrides.

  • Package Categories: Support for organizing dependencies into different groups beyond just default and development packages.

Quick Start

Image for: Quick Start¶

Installation

The recommended way to install pipenv on most platforms is to install from PyPI using pip:

$ pip install --user pipenv

For more detailed installation instructions, see the Installing Pipenv chapter.

Basic Usage

Create a new project:

$ mkdir my_project && cd my_project
$ pipenv install

Install packages:

$ pipenv install requests

Create a Python file (e.g., main.py):

import requests

response = requests.get('https://httpbin.org/ip')
print(f'Your IP is {response.json()["origin"]}')

Run your script:

$ pipenv run python main.py

Activate the virtual environment:

$ pipenv shell

Pipenv Documentation

Image for: Pipenv Documentation¶

Pipenv Documentation

Contribution Guides

Image for: Contribution Guides¶

✨🍰✨