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:
pipenv [OPTIONS] COMMAND [ARGS]...
Global Options¶
These options can be used with any Pipenv command:
Option |
Description |
|---|---|
|
Output project home information |
|
Output virtualenv information |
|
Output Python interpreter information |
|
Output environment variable options |
|
Remove the virtualenv |
|
Minimal output |
|
Display manpage |
|
Output diagnostic information for GitHub issues |
|
Enable site-packages for the virtualenv |
|
Specify which Python version to use |
|
Clear caches (pipenv, pip) |
|
Quiet mode |
|
Verbose mode |
|
Specify a PyPI mirror |
|
Show the version and exit |
|
Show 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.
pipenv install [OPTIONS] [PACKAGES]...
Options¶
Option |
Description |
|---|---|
|
Install both development and default packages |
|
Install packages to specified category groups |
|
Install to system Python instead of virtualenv |
|
Abort if Pipfile.lock is out-of-date |
|
Install from Pipfile.lock, ignoring Pipfile |
|
Skip locking of dependencies |
|
Import a requirements.txt file |
|
Pass additional arguments to pip |
|
Specify which Python version to use |
|
Show what would happen without making changes |
Examples¶
Install a specific package:
$ pipenv install requests
Install a package with version constraint:
$ pipenv install "requests>=2.20.0"
Install a development dependency:
$ pipenv install pytest --dev
Install from requirements.txt:
$ pipenv install -r requirements.txt
Install with deployment check:
$ pipenv install --deploy
uninstall¶
Uninstalls a provided package and removes it from Pipfile.
pipenv uninstall [OPTIONS] [PACKAGES]...
Options¶
Option |
Description |
|---|---|
|
Purge all files from the virtual environment |
|
Remove all development packages |
|
Skip locking of dependencies |
|
Uninstall from specified category groups |
Examples¶
Uninstall a package:
$ pipenv uninstall requests
Uninstall all packages:
$ pipenv uninstall --all
Uninstall all development packages:
$ pipenv uninstall --all-dev
lock¶
Generates Pipfile.lock with all dependencies and their sub-dependencies.
pipenv lock [OPTIONS]
Options¶
Option |
Description |
|---|---|
|
Allow pre-releases |
|
Clear the dependency cache |
|
Show verbose output |
|
Lock specified categories only |
|
Keep outdated dependencies |
|
Specify which Python version to use for resolution |
|
Pass additional arguments to pip |
Examples¶
Generate a lock file:
$ pipenv lock
Generate a lock file with pre-releases:
$ pipenv lock --pre
Lock specific categories:
$ pipenv lock --categories="docs,tests"
sync¶
Installs all packages specified in Pipfile.lock.
pipenv sync [OPTIONS]
Options¶
Option |
Description |
|---|---|
|
Install both development and default packages |
|
Install packages from specified category groups |
|
Specify which Python version to use |
|
Pass additional arguments to pip |
Examples¶
Install packages from lock file:
$ pipenv sync
Install development packages too:
$ pipenv sync --dev
Install specific categories:
$ pipenv sync --categories="docs,tests"
update¶
Runs lock when no packages are specified, or upgrade for specific packages, and then sync.
pipenv update [OPTIONS] [PACKAGES]...
Options¶
Option |
Description |
|---|---|
|
Update development packages |
|
Update packages in specified categories |
|
List out-of-date dependencies |
|
Show what would happen without making changes |
|
Specify which Python version to use |
|
Clear the dependency cache |
Examples¶
Update all packages:
$ pipenv update
Update specific packages:
$ pipenv update requests pytest
Check for outdated packages:
$ pipenv update --outdated
upgrade¶
Updates the lock file for specified dependencies without installing them.
pipenv upgrade [OPTIONS] [PACKAGES]...
Options¶
Option |
Description |
|---|---|
|
Upgrade development packages |
|
Upgrade packages in specified categories |
|
Show what would happen without making changes |
|
Specify which Python version to use |
|
Clear the dependency cache |
Examples¶
Upgrade a specific package in the lock file:
$ pipenv upgrade requests
Upgrade development packages:
$ pipenv upgrade --dev
check¶
Checks for security vulnerabilities and PEP 508 marker compliance.
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¶
Option |
Description |
|---|---|
|
Path or URL to a PyUp Safety vulnerabilities database |
|
Ignore specified vulnerability |
|
Specify output format |
|
Safety API key from PyUp.io |
|
Use installed packages instead of lockfile |
|
Check packages in specified categories |
|
Automatically install safety if not already installed |
|
Use the new scan command instead |
Examples¶
Check for vulnerabilities:
$ pipenv check
Check with a specific output format:
$ pipenv check --output json
Use the new scan command:
$ pipenv check --scan
scan¶
Enhanced security scanning (replacement for check).
pipenv scan [OPTIONS]
Options¶
Similar to the check command, with enhanced functionality.
Examples¶
Scan for vulnerabilities:
$ pipenv scan
Scan with a specific output format:
$ pipenv scan --output json
run¶
Spawns a command installed into the virtualenv.
pipenv run [OPTIONS] COMMAND [ARGS]...
Examples¶
Run a Python script:
$ pipenv run python app.py
Run tests:
$ pipenv run pytest
Run a custom script defined in Pipfile:
$ pipenv run start
shell¶
Spawns a shell within the virtualenv.
pipenv shell [OPTIONS] [SHELL_ARGS]...
Options¶
Option |
Description |
|---|---|
|
Use a fancy shell activation method |
Examples¶
Activate the virtual environment:
$ pipenv shell
Activate with fancy mode:
$ pipenv shell --fancy
graph¶
Displays currently-installed dependency graph information.
pipenv graph [OPTIONS]
Options¶
Option |
Description |
|---|---|
|
Output graph in bare format |
|
Output graph in JSON format |
|
Output graph as JSON tree |
|
Reversed dependency graph |
Examples¶
Show dependency graph:
$ pipenv graph
Show reverse dependencies:
$ pipenv graph --reverse
Show JSON output:
$ pipenv graph --json
clean¶
Uninstalls all packages not specified in Pipfile.lock.
pipenv clean [OPTIONS]
Options¶
Option |
Description |
|---|---|
|
Show what would be removed without removing |
Examples¶
Remove unused packages:
$ pipenv clean
Preview what would be removed:
$ pipenv clean --dry-run
requirements¶
Generate a requirements.txt from Pipfile.lock.
pipenv requirements [OPTIONS]
Options¶
Option |
Description |
|---|---|
|
Include development packages |
|
Only include development packages |
|
Include package hashes |
|
Exclude PEP 508 markers |
|
Include packages from specified categories |
Examples¶
Generate requirements.txt:
$ pipenv requirements > requirements.txt
Include development packages:
$ pipenv requirements --dev > requirements-dev.txt
Include hashes:
$ pipenv requirements --hash > requirements.txt
scripts¶
Lists scripts defined in the current environment config.
pipenv scripts [OPTIONS]
Examples¶
List available scripts:
$ pipenv scripts
open¶
Opens a Python module in your editor.
pipenv open [OPTIONS] MODULE
Examples¶
Open the requests module:
$ pipenv open requests
Open with a specific editor:
$ EDITOR=code pipenv open requests
verify¶
Verifies that the Pipfile.lock is up-to-date with the Pipfile.
pipenv verify [OPTIONS]
Examples¶
Verify lock file integrity:
$ pipenv verify
Environment Variables¶
Pipenv’s behavior can be customized through environment variables. Here are some commonly used ones:
Variable |
Description |
|---|---|
|
Create virtualenv in project directory |
|
Ignore active virtualenvs |
|
Custom Pipfile location |
|
Custom .env file location |
|
Custom cache directory |
|
Timeout for pip operations |
|
Skip lock file generation |
|
PyPI mirror URL |
|
Maximum depth for dependency resolution |
|
Don’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.locklock: Updates Pipfile.lock without installing packagessync: Installs packages from Pipfile.lock without modifying itupdate: Combineslockandsync(orupgradeandsyncfor specific packages)upgrade: Updates Pipfile.lock for specific packages without installing themuninstall: Removes packages from virtualenv and Pipfileclean: Removes packages from virtualenv that aren’t in Pipfile.lock
Best Practices¶
CI/CD Pipelines¶
For continuous integration and deployment:
# 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:
# Install only production dependencies
$ pipenv install --deploy
# Or for systems without virtualenv support
$ pipenv install --system --deploy
Development Workflow¶
For daily development:
# 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 lockto update itDependency conflicts: Try
pipenv lock --clearto 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.