docs/commands.md
This document provides a comprehensive reference for all Pipenv commands, including detailed explanations, options, and practical examples.
| Command | Description |
|---|---|
install | Install packages or create/update virtual environment |
uninstall | Remove packages from virtual environment and Pipfile |
lock | Generate Pipfile.lock with dependencies and hashes |
sync | Install packages from Pipfile.lock without modifying the lockfile |
update | Update dependencies and install them (lock + sync) |
upgrade | Update the lock of specified dependencies without installing |
check | Check for security vulnerabilities and PEP 508 compliance (use --scan for enhanced scanning) |
shell | Spawn a shell within the virtual environment |
run | Run a command within the virtual environment |
graph | Display dependency graph information |
remove | Remove the virtualenv for the current project |
clean | Remove packages not specified in Pipfile.lock |
verify | Verify the Pipfile.lock hash is up-to-date |
requirements | Generate a requirements.txt from Pipfile.lock |
scripts | List scripts defined in the environment |
open | Open a Python module in your editor |
The install command is used for installing packages into the Pipenv virtual environment and updating your Pipfile and Pipfile.lock.
$ pipenv install [package_name]
When run without arguments, pipenv install will create a virtual environment if one doesn't exist, and install all packages specified in the Pipfile.
When a package name is provided, it will install that package, add it to the Pipfile, and update the Pipfile.lock.
Install a specific package:
$ pipenv install requests
Install a package with version constraint:
$ pipenv install "requests>=2.20.0"
Install a package from a Git repository:
$ pipenv install -e git+https://github.com/requests/requests.git@master#egg=requests
Install a package as a development dependency:
$ pipenv install pytest --dev
Install packages from a requirements.txt file:
$ pipenv install -r requirements.txt
| Option | Description |
|---|---|
--dev | Install both development and default packages from Pipfile |
--categories | Install packages to the specified category groups |
--deploy | Abort if Pipfile.lock is out-of-date |
--ignore-pipfile | Install from Pipfile.lock, ignoring Pipfile |
--system | Install to system Python instead of virtual environment |
--python | Specify which Python version to use |
--requirements, -r | Import a requirements.txt file |
--extra-pip-args | Pass additional arguments to pip |
Prior to Pipenv 2024, the install command would relock the lock file every time it was run. Based on user feedback, this behavior was changed so that install only updates the lock when adding or changing a package. To relock the entire set of Pipfile specifiers, use pipenv lock.
The --ignore-pipfile flag is similar to pipenv sync, but with an important difference:
pipenv install --ignore-pipfile: Installs packages from Pipfile.lock, ignoring the Pipfile. However, it may still attempt to re-lock your dependencies unless you also use the --deploy flag.
pipenv sync: Installs packages exactly as specified in Pipfile.lock without ever attempting to re-lock. This is considered an atomic operation.
For deployment scenarios, pipenv sync is the recommended command because it guarantees that no modifications will be made to your lock file.
# Development: may re-lock if needed
$ pipenv install --ignore-pipfile
# Production: never re-locks, fails if lock is out of date
$ pipenv install --ignore-pipfile --deploy
# Production (recommended): atomic install from lock file
$ pipenv sync
The sync command installs dependencies from the Pipfile.lock without making any changes to the lockfile. This is useful for deployment scenarios where you want to ensure exact package versions are installed.
$ pipenv sync
Install only default packages:
$ pipenv sync
Install both default and development packages:
$ pipenv sync --dev
Install all categories (default, dev, and any custom categories):
$ pipenv sync --all
Install specific package categories:
$ pipenv sync --categories="tests,docs"
| Option | Description |
|---|---|
--dev | Install both development and default packages |
--all | Install packages from all categories defined in the Pipfile |
--categories | Install packages from specified category groups |
The uninstall command removes packages from your virtual environment and Pipfile.
$ pipenv uninstall [package_name]
Uninstall a specific package:
$ pipenv uninstall requests
Uninstall multiple packages:
$ pipenv uninstall requests pytest
Uninstall all packages:
$ pipenv uninstall --all
Uninstall all development packages:
$ pipenv uninstall --all-dev
Uninstall a dev package using --dev flag:
$ pipenv uninstall ruff --dev
| Option | Description |
|---|---|
--all | Remove all packages from virtual environment |
--all-dev | Remove all development packages |
--dev | Uninstall package from dev-packages section |
--categories | Specify which categories to uninstall from |
--skip-lock | Don't update Pipfile.lock after uninstalling |
The lock command generates a Pipfile.lock file, which contains all dependencies (including sub-dependencies) with their exact versions and hashes.
$ pipenv lock
Generate a lockfile including pre-release versions:
$ pipenv lock --pre
Generate a lockfile for a specific Python version:
$ pipenv lock --python 3.9
| Option | Description |
|---|---|
--pre | Allow pre-releases to be pinned |
--clear | Clear the dependency cache |
--python | Specify which Python version to use for resolution |
--categories | Lock specified categories only |
The update command runs lock when no packages are specified, or upgrade for specific packages, and then runs sync to install the updated packages.
$ pipenv update [package_name]
Update all packages:
$ pipenv update
Update specific packages:
$ pipenv update requests pytest
Check for outdated packages without updating:
$ pipenv update --outdated
| Option | Description |
|---|---|
--outdated | List out-of-date dependencies |
--dev | Update development packages |
--categories | Update packages in specified categories |
The upgrade command updates the lock file for specified dependencies and their sub-dependencies, but does not install the updated packages.
$ pipenv upgrade [package_name]
Upgrade a specific package in the lock file:
$ pipenv upgrade requests
Upgrade multiple packages:
$ pipenv upgrade requests pytest
| Option | Description |
|---|---|
--dev | Upgrade development packages |
--categories | Upgrade packages in specified categories |
The check command checks for security vulnerabilities in your dependencies and verifies that your environment meets PEP 508 requirements.
$ pipenv check
Check with a specific vulnerability database:
$ pipenv check --db /path/to/db
Check with a specific output format:
$ pipenv check --output json
| Option | Description |
|---|---|
--db | Path or URL to a PyUp Safety vulnerabilities database |
--ignore, -i | Ignore specified vulnerability |
--output | Specify output format (screen, text, json, bare) |
--key | Safety API key from PyUp.io |
--use-installed | Use installed packages instead of lockfile |
--categories | Check packages in specified categories |
--auto-install | Automatically install safety if not already installed |
--scan | Enable the newer version of the check command with improved functionality. |
Note: The check command is deprecated and will be unsupported beyond June 1, 2025. Use pipenv check --scan for enhanced security scanning.
The run command executes a command within the context of the virtual environment.
$ pipenv run [command]
Run a Python script:
$ pipenv run python main.py
Run a test suite:
$ pipenv run pytest
Run a custom script defined in Pipfile:
$ pipenv run start
The shell command spawns a shell within the virtual environment, allowing you to interact with your installed packages.
$ pipenv shell
Activate the shell with a specific shell program:
$ pipenv shell --fancy
| Option | Description |
|---|---|
--fancy | Use a fancy shell activation method |
The graph command displays a dependency graph of your installed packages.
$ pipenv graph
Show a dependency graph with reverse dependencies:
$ pipenv graph --reverse
| Option | Description |
|---|---|
--bare | Output graph in bare format |
--json | Output graph in JSON format |
--json-tree | Output graph as JSON tree |
--reverse | Reversed dependency graph |
The requirements command generates a requirements.txt file from your Pipfile.lock.
$ pipenv requirements
Generate requirements with hashes:
$ pipenv requirements --hash
Generate requirements for development packages only:
$ pipenv requirements --dev-only
Generate requirements for specific categories:
$ pipenv requirements --categories="tests,docs"
| Option | Description |
|---|---|
--dev | Include development packages |
--dev-only | Only include development packages |
--hash | Include package hashes |
--exclude-markers | Exclude PEP 508 markers |
--categories | Include packages from specified categories |
The remove command deletes the virtualenv associated with the current project.
$ pipenv remove
Remove the current project's virtualenv:
$ pipenv remove
Removing virtualenv (/home/user/.local/share/virtualenvs/myproject-abc123)...
You can then recreate it with pipenv install.
Note: The legacy
pipenv --rmflag performs the same action but is deprecated and will be removed in a future release. Usepipenv removeinstead.
The clean command uninstalls all packages not specified in Pipfile.lock.
$ pipenv clean
Dry run to see what would be removed:
$ pipenv clean --dry-run
| Option | Description |
|---|---|
--dry-run | Show what would be removed without removing |
The verify command checks that the Pipfile.lock is up-to-date with the Pipfile.
$ pipenv verify
This command is useful in CI/CD pipelines to ensure that the lock file is synchronized with the Pipfile before deployment.
The scripts command lists scripts defined in the current environment configuration.
$ pipenv scripts
The open command opens a Python module in your editor.
$ pipenv open [module_name]
Open the requests module in your editor:
$ pipenv open requests
Note: This command uses the EDITOR environment variable to determine which editor to use.