Pipenv Commands Reference¶
This document provides a comprehensive reference for all Pipenv commands, including detailed explanations, options, and practical examples.
Core Commands Overview¶
Command |
Description |
---|---|
|
Install packages or create/update virtual environment |
|
Remove packages from virtual environment and Pipfile |
|
Generate Pipfile.lock with dependencies and hashes |
|
Install packages from Pipfile.lock without modifying the lockfile |
|
Update dependencies and install them (lock + sync) |
|
Update the lock of specified dependencies without installing |
|
Check for security vulnerabilities and PEP 508 compliance |
|
Enhanced security scanning (replacement for check) |
|
Spawn a shell within the virtual environment |
|
Run a command within the virtual environment |
|
Display dependency graph information |
|
Remove packages not specified in Pipfile.lock |
|
Verify the Pipfile.lock hash is up-to-date |
|
Generate a requirements.txt from Pipfile.lock |
|
List scripts defined in the environment |
|
Open a Python module in your editor |
install¶
The install
command is used for installing packages into the Pipenv virtual environment and updating your Pipfile and Pipfile.lock.
Basic Usage¶
$ 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.
Examples¶
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
Options¶
Option |
Description |
---|---|
|
Install both development and default packages from Pipfile |
|
Install packages to the specified category groups |
|
Abort if Pipfile.lock is out-of-date |
|
Install from Pipfile.lock, ignoring Pipfile |
|
Install to system Python instead of virtual environment |
|
Specify which Python version to use |
|
Import a requirements.txt file |
|
Pass additional arguments to pip |
Important Note¶
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
.
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.
Basic Usage¶
$ pipenv sync
Examples¶
Install only default packages:
$ pipenv sync
Install both default and development packages:
$ pipenv sync --dev
Install specific package categories:
$ pipenv sync --categories="tests,docs"
Options¶
Option |
Description |
---|---|
|
Install both development and default packages |
|
Install packages from specified category groups |
uninstall¶
The uninstall
command removes packages from your virtual environment and Pipfile.
Basic Usage¶
$ pipenv uninstall [package_name]
Examples¶
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
Options¶
Option |
Description |
---|---|
|
Remove all packages from virtual environment |
|
Remove all development packages |
|
Don’t update Pipfile.lock after uninstalling |
lock¶
The lock
command generates a Pipfile.lock file, which contains all dependencies (including sub-dependencies) with their exact versions and hashes.
Basic Usage¶
$ pipenv lock
Examples¶
Generate a lockfile including pre-release versions:
$ pipenv lock --pre
Generate a lockfile for a specific Python version:
$ pipenv lock --python 3.9
Options¶
Option |
Description |
---|---|
|
Allow pre-releases to be pinned |
|
Clear the dependency cache |
|
Specify which Python version to use for resolution |
|
Lock specified categories only |
update¶
The update
command runs lock
when no packages are specified, or upgrade
for specific packages, and then runs sync
to install the updated packages.
Basic Usage¶
$ pipenv update [package_name]
Examples¶
Update all packages:
$ pipenv update
Update specific packages:
$ pipenv update requests pytest
Check for outdated packages without updating:
$ pipenv update --outdated
Options¶
Option |
Description |
---|---|
|
List out-of-date dependencies |
|
Update development packages |
|
Update packages in specified categories |
upgrade¶
The upgrade
command updates the lock file for specified dependencies and their sub-dependencies, but does not install the updated packages.
Basic Usage¶
$ pipenv upgrade [package_name]
Examples¶
Upgrade a specific package in the lock file:
$ pipenv upgrade requests
Upgrade multiple packages:
$ pipenv upgrade requests pytest
Options¶
Option |
Description |
---|---|
|
Upgrade development packages |
|
Upgrade packages in specified categories |
check¶
The check
command checks for security vulnerabilities in your dependencies and verifies that your environment meets PEP 508 requirements.
Basic Usage¶
$ pipenv check
Examples¶
Check with a specific vulnerability database:
$ pipenv check --db /path/to/db
Check with a specific output format:
$ pipenv check --output json
Options¶
Option |
Description |
---|---|
|
Path or URL to a PyUp Safety vulnerabilities database |
|
Ignore specified vulnerability |
|
Specify output format (screen, text, json, bare) |
|
Safety API key from PyUp.io |
|
Use installed packages instead of lockfile |
|
Check packages in specified categories |
|
Automatically install safety if not already installed |
|
Enable the newer version of the check command with improved functionality. |
Note: The check command is deprecated and will be unsupported beyond June 1, 2024. Use the scan
command instead.
run¶
The run
command executes a command within the context of the virtual environment.
Basic Usage¶
$ pipenv run [command]
Examples¶
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
shell¶
The shell
command spawns a shell within the virtual environment, allowing you to interact with your installed packages.
Basic Usage¶
$ pipenv shell
Examples¶
Activate the shell with a specific shell program:
$ pipenv shell --fancy
Options¶
Option |
Description |
---|---|
|
Use a fancy shell activation method |
graph¶
The graph
command displays a dependency graph of your installed packages.
Basic Usage¶
$ pipenv graph
Examples¶
Show a dependency graph with reverse dependencies:
$ pipenv graph --reverse
Options¶
Option |
Description |
---|---|
|
Output graph in bare format |
|
Output graph in JSON format |
|
Output graph as JSON tree |
|
Reversed dependency graph |
requirements¶
The requirements
command generates a requirements.txt file from your Pipfile.lock.
Basic Usage¶
$ pipenv requirements
Examples¶
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"
Options¶
Option |
Description |
---|---|
|
Include development packages |
|
Only include development packages |
|
Include package hashes |
|
Exclude PEP 508 markers |
|
Include packages from specified categories |
clean¶
The clean
command uninstalls all packages not specified in Pipfile.lock.
Basic Usage¶
$ pipenv clean
Examples¶
Dry run to see what would be removed:
$ pipenv clean --dry-run
Options¶
Option |
Description |
---|---|
|
Show what would be removed without removing |
verify¶
The verify
command checks that the Pipfile.lock is up-to-date with the Pipfile.
Basic Usage¶
$ pipenv verify
This command is useful in CI/CD pipelines to ensure that the lock file is synchronized with the Pipfile before deployment.
scripts¶
The scripts
command lists scripts defined in the current environment configuration.
Basic Usage¶
$ pipenv scripts
open¶
The open
command opens a Python module in your editor.
Basic Usage¶
$ pipenv open [module_name]
Examples¶
Open the requests module in your editor:
$ pipenv open requests
Note: This command uses the EDITOR
environment variable to determine which editor to use.