pipenv
Manage project dependencies in isolated environments
TLDR
Create a new project
Create a new project using Python 3
Install a package
Install all the dependencies for a project
Install all the dependencies for a project (including dev packages)
Uninstall a package
Start a shell within the created virtual environment
Generate a requirements.txt (list of dependencies) for a project
SYNOPSIS
pipenv [options] <command> [command_options_and_args]
Common Commands:
install [packages] [options] - Installs packages and manages the Pipfile/Pipfile.lock.
shell - Spawns a shell within the virtual environment.
run <command> [args] - Runs a command within the virtual environment.
sync - Installs all packages specified in Pipfile.lock.
uninstall [packages] [options] - Uninstalls packages.
update [packages] [options] - Updates packages to their latest versions.
graph - Displays a graph of installed dependencies.
check - Checks for security vulnerabilities and PEP 508 markers.
PARAMETERS
--python <path_to_python>
Specifies a Python interpreter to use for the virtual environment (e.g., --python 3.9 or --python /usr/bin/python3.10).
--dev
Installs development packages defined in the [dev-packages] section of the Pipfile.
--pre
Allows the installation of pre-release versions of packages.
--skip-lock
Skips the generation or update of Pipfile.lock, which can speed up operations but sacrifices determinism.
--system
Forces pipenv to use the system's pip and global Python environment instead of creating a virtual environment.
--pypi-mirror <url>
Specifies a PyPI mirror URL to use for package lookups instead of the default PyPI.
--require-virtualenv
Ensures that pipenv operates within an active virtual environment; aborts if not.
--where
Displays the path to the project directory where pipenv is operating.
--venv
Displays the path to the virtual environment associated with the current project.
--rm
Removes the virtual environment associated with the current project.
--bare
Produces minimal output, useful for scripting or CI/CD pipelines.
DESCRIPTION
pipenv is a Python dependency management tool that combines the best of pip and virtualenv into a single utility. It aims to simplify the Python development workflow by managing virtual environments and project dependencies in a consistent and reproducible manner.
Instead of requirements.txt, pipenv uses a Pipfile to explicitly declare project dependencies. It automatically creates and manages a project-specific virtual environment, ensuring that your project's dependencies are isolated from other Python projects and the system's global Python installation.
Key features include cryptographic hashing of dependencies for deterministic builds via Pipfile.lock, a unified workflow for installing, uninstalling, and updating packages, and convenient commands like pipenv shell to activate the environment or pipenv run to execute commands within it. It streamlines setting up development environments and deploying applications, making dependency management less error-prone and more efficient.
CAVEATS
pipenv, while powerful, has been subject to debate regarding its complexity and sometimes slower performance compared to using pip and virtualenv separately. Its strict dependency resolution and reliance on Pipfile.lock can sometimes lead to issues when dealing with complex dependency graphs or private package indexes that are not well-behaved. Community adoption has varied, with some developers preferring newer alternatives like Poetry for their opinionated workflows, or sticking to the simpler pip + venv approach.
PIPFILE AND PIPFILE.LOCK
Pipfile is a high-level declaration of project dependencies, replacing requirements.txt. It's more declarative, supporting different environments (e.g., development dependencies). Pipfile.lock is a generated file that cryptographically hashes all package dependencies and sub-dependencies, ensuring deterministic builds across different machines and deployments. It guarantees that running pipenv sync will install the exact same versions of packages every time.
VIRTUAL ENVIRONMENT MANAGEMENT
pipenv automatically creates and manages a virtual environment for each project. By default, it places these environments in a central location (e.g., ~/.local/share/virtualenvs), but it can also be configured to create them within the project directory (by setting the PIPENV_VENV_IN_PROJECT environment variable to 1).
HISTORY
pipenv was created by Kenneth Reitz in 2017 with the goal of bringing the best features from various package managers (like npm, yarn, bundler) to the Python ecosystem. It gained significant initial traction and was, for a period, considered the Python Packaging Authority's (PyPA) recommended tool for application dependency management. However, PyPA later shifted its official recommendation back to the more fundamental tools, pip and venv, citing pipenv's complexity and specific design choices. Despite this, pipenv continues to be actively maintained and widely used by many Python developers for its comprehensive features and streamlined workflow, especially for project-based development.
SEE ALSO
pip(1), virtualenv(1), python(1), venv(1), poetry(1)