Back to Pipenv

Pipenv Command Line Interface

docs/cli.md

2026.6.113.1 KB
Original Source

Pipenv Command Line Interface

This comprehensive guide covers Pipenv's command line interface, including all available commands, options, and usage examples.

Overview

Pipenv provides a powerful command line interface (CLI) that simplifies Python dependency management and virtual environment workflows. The CLI follows a consistent pattern:

bash
pipenv [OPTIONS] COMMAND [ARGS]...

Global Options

These options can be used with any Pipenv command:

OptionDescription
--whereOutput project home information
--venvOutput virtualenv information
--pyOutput Python interpreter information
--envsOutput environment variable options
--rmRemove the virtualenv (deprecated: use pipenv remove instead)
--bareMinimal output
--manDisplay manpage
--supportOutput diagnostic information for GitHub issues
--site-packagesEnable site-packages for the virtualenv
--python TEXTSpecify which Python version to use
--clearClear caches (pipenv, pip)
-q, --quietQuiet mode
-v, --verboseVerbose mode
--pypi-mirror TEXTSpecify a PyPI mirror
--versionShow the version and exit
-h, --helpShow help message and exit

Core Commands

install

Installs packages and adds them to Pipfile, or installs all packages from Pipfile.lock if no packages are specified.

bash
pipenv install [OPTIONS] [PACKAGES]...

Options

OptionDescription
--devInstall both development and default packages
--categories TEXTInstall packages to specified category groups
--systemInstall to system Python instead of virtualenv
--deployAbort if Pipfile.lock is out-of-date
--ignore-pipfileInstall from Pipfile.lock, ignoring Pipfile
--skip-lockSkip locking of dependencies
--requirements, -r TEXTImport a requirements.txt file
--extra-pip-args TEXTPass additional arguments to pip
--python TEXTSpecify which Python version to use
--dry-runShow what would happen without making changes

Examples

Install a specific package:

bash
$ pipenv install requests

Install a package with version constraint:

bash
$ pipenv install "requests>=2.20.0"

Install a development dependency:

bash
$ pipenv install pytest --dev

Install from requirements.txt:

bash
$ pipenv install -r requirements.txt

Install with deployment check:

bash
$ pipenv install --deploy

uninstall

Uninstalls a provided package and removes it from Pipfile.

bash
pipenv uninstall [OPTIONS] [PACKAGES]...

Options

OptionDescription
--allPurge all files from the virtual environment
--all-devRemove all development packages
--skip-lockSkip locking of dependencies
--categories TEXTUninstall from specified category groups

Examples

Uninstall a package:

bash
$ pipenv uninstall requests

Uninstall all packages:

bash
$ pipenv uninstall --all

Uninstall all development packages:

bash
$ pipenv uninstall --all-dev

lock

Generates Pipfile.lock with all dependencies and their sub-dependencies.

bash
pipenv lock [OPTIONS]

Options

OptionDescription
--preAllow pre-releases
--clearClear the dependency cache
--verboseShow verbose output
--categories TEXTLock specified categories only
--keep-outdatedKeep outdated dependencies
--python TEXTSpecify which Python version to use for resolution
--extra-pip-args TEXTPass additional arguments to pip

Examples

Generate a lock file:

bash
$ pipenv lock

Generate a lock file with pre-releases:

bash
$ pipenv lock --pre

Lock specific categories:

bash
$ pipenv lock --categories="docs,tests"

sync

Installs all packages specified in Pipfile.lock.

bash
pipenv sync [OPTIONS]

Options

OptionDescription
--devInstall both development and default packages
--allInstall packages from all categories defined in the Pipfile
--categories TEXTInstall packages from specified category groups
--python TEXTSpecify which Python version to use
--extra-pip-args TEXTPass additional arguments to pip

Examples

Install packages from lock file:

bash
$ pipenv sync

Install development packages too:

bash
$ pipenv sync --dev

Install all categories (default, dev, and any custom categories):

bash
$ pipenv sync --all

Install specific categories:

bash
$ pipenv sync --categories="docs,tests"

update

Runs lock when no packages are specified, or upgrade for specific packages, and then sync.

bash
pipenv update [OPTIONS] [PACKAGES]...

Options

OptionDescription
--devUpdate development packages
--allUpdate packages from all categories defined in the Pipfile
--categories TEXTUpdate packages in specified categories
--outdatedList out-of-date dependencies
--dry-runShow what would happen without making changes
--python TEXTSpecify which Python version to use
--clearClear the dependency cache

Examples

Update all packages:

bash
$ pipenv update

Update specific packages:

bash
$ pipenv update requests pytest

Check for outdated packages:

bash
$ pipenv update --outdated

upgrade

Updates the lock file for specified dependencies without installing them.

bash
pipenv upgrade [OPTIONS] [PACKAGES]...

Options

OptionDescription
--devUpgrade development packages
--allUpgrade packages from all categories defined in the Pipfile
--categories TEXTUpgrade packages in specified categories
--dry-runShow what would happen without making changes
--python TEXTSpecify which Python version to use
--clearClear the dependency cache

Examples

Upgrade a specific package in the lock file:

bash
$ pipenv upgrade requests

Upgrade development packages:

bash
$ pipenv upgrade --dev

check

Checks for security vulnerabilities and PEP 508 marker compliance.

bash
pipenv check [OPTIONS]

Note: The check command is deprecated and will be unsupported beyond 01 June 2025. In future versions, the check command will run the scan command by default. Use the --scan option to run the new scan command now.

Options

OptionDescription
--db TEXTPath or URL to a PyUp Safety vulnerabilities database
--ignore, -i TEXTIgnore specified vulnerability
--output [screen|text|json|bare]Specify output format
--key TEXTSafety API key from PyUp.io
--use-installedUse installed packages instead of lockfile
--categories TEXTCheck packages in specified categories
--auto-installAutomatically install safety if not already installed
--scanUse the new scan command instead

Examples

Check for vulnerabilities:

bash
$ pipenv check

Check with a specific output format:

bash
$ pipenv check --output json

Use the new scan command:

bash
$ pipenv check --scan

scan

Enhanced security scanning (replacement for check).

bash
pipenv scan [OPTIONS]

Options

Similar to the check command, with enhanced functionality.

Examples

Scan for vulnerabilities:

bash
$ pipenv scan

Scan with a specific output format:

bash
$ pipenv scan --output json

run

Spawns a command installed into the virtualenv.

bash
pipenv run [OPTIONS] COMMAND [ARGS]...

Examples

Run a Python script:

bash
$ pipenv run python app.py

Run tests:

bash
$ pipenv run pytest

Run a custom script defined in Pipfile:

bash
$ pipenv run start

shell

Spawns a shell within the virtualenv.

bash
pipenv shell [OPTIONS] [SHELL_ARGS]...

Options

OptionDescription
--fancyUse a fancy shell activation method

Examples

Activate the virtual environment:

bash
$ pipenv shell

Activate with fancy mode:

bash
$ pipenv shell --fancy

graph

Displays currently-installed dependency graph information.

bash
pipenv graph [OPTIONS]

Options

OptionDescription
--bareOutput graph in bare format
--jsonOutput graph in JSON format
--json-treeOutput graph as JSON tree
--reverseReversed dependency graph

Examples

Show dependency graph:

bash
$ pipenv graph

Show reverse dependencies:

bash
$ pipenv graph --reverse

Show JSON output:

bash
$ pipenv graph --json

clean

Uninstalls all packages not specified in Pipfile.lock.

bash
pipenv clean [OPTIONS]

Options

OptionDescription
--dry-runShow what would be removed without removing

Examples

Remove unused packages:

bash
$ pipenv clean

Preview what would be removed:

bash
$ pipenv clean --dry-run

requirements

Generate a requirements.txt from Pipfile.lock.

bash
pipenv requirements [OPTIONS]

Options

OptionDescription
--devInclude development packages
--dev-onlyOnly include development packages
--hashInclude package hashes
--exclude-markersExclude PEP 508 markers
--categories TEXTInclude packages from specified categories

Examples

Generate requirements.txt:

bash
$ pipenv requirements > requirements.txt

Include development packages:

bash
$ pipenv requirements --dev > requirements-dev.txt

Include hashes:

bash
$ pipenv requirements --hash > requirements.txt

scripts

Lists scripts defined in the current environment config.

bash
pipenv scripts [OPTIONS]

Examples

List available scripts:

bash
$ pipenv scripts

open

Opens a Python module in your editor.

bash
pipenv open [OPTIONS] MODULE

Examples

Open the requests module:

bash
$ pipenv open requests

Open with a specific editor:

bash
$ EDITOR=code pipenv open requests

verify

Verifies that the Pipfile.lock is up-to-date with the Pipfile.

bash
pipenv verify [OPTIONS]

Examples

Verify lock file integrity:

bash
$ pipenv verify

Environment Variables

Pipenv's behavior can be customized through environment variables. Here are some commonly used ones:

VariableDescription
PIPENV_VENV_IN_PROJECTCreate virtualenv in project directory
PIPENV_IGNORE_VIRTUALENVSIgnore active virtualenvs
PIPENV_PIPFILECustom Pipfile location
PIPENV_DOTENV_LOCATIONCustom .env file location
PIPENV_CACHE_DIRCustom cache directory
PIPENV_TIMEOUTTimeout for pip operations
PIPENV_SKIP_LOCKSkip lock file generation
PIPENV_PYPI_MIRRORPyPI mirror URL
PIPENV_MAX_DEPTHMaximum depth for dependency resolution
PIPENV_DONT_LOAD_ENVDon't load .env files

For a complete list, see the Configuration page.

Command Relationships

Understanding how Pipenv commands relate to each other can help you use them more effectively:

  • install: Adds packages to Pipfile and updates Pipfile.lock
  • lock: Updates Pipfile.lock without installing packages
  • sync: Installs packages from Pipfile.lock without modifying it
  • update: Combines lock and sync (or upgrade and sync for specific packages)
  • upgrade: Updates Pipfile.lock for specific packages without installing them
  • uninstall: Removes packages from virtualenv and Pipfile
  • clean: Removes packages from virtualenv that aren't in Pipfile.lock
  • remove: Deletes the entire virtualenv for the current project

Best Practices

CI/CD Pipelines

For continuous integration and deployment:

bash
# Verify the lock file is up-to-date
$ pipenv verify

# Install dependencies
$ pipenv sync --dev

# Run tests
$ pipenv run pytest

Production Deployment

For production environments:

bash
# Install only production dependencies
$ pipenv install --deploy

# Or for systems without virtualenv support
$ pipenv install --system --deploy

Development Workflow

For daily development:

bash
# Install dependencies including development packages
$ pipenv install --dev

# Activate environment
$ pipenv shell

# Run your application
$ python app.py

Troubleshooting

Common Issues

  • Command not found: Ensure Pipenv is installed and in your PATH
  • Pipfile not found: Run commands from your project directory
  • Lock file out of date: Run pipenv lock to update it
  • Dependency conflicts: Try pipenv lock --clear to clear the cache

For more troubleshooting tips, see the Troubleshooting guide.

Conclusion

Pipenv's CLI provides a comprehensive set of commands for managing Python dependencies and virtual environments. By understanding these commands and their options, you can streamline your Python development workflow and ensure consistent, reproducible environments.