Install pipenv
with pip
- pip install pipenv
Install packages (creates the virtual environment) - pipenv install <package_name>
. Ex: pipenv install requests
Activate a virtual environment - pipenv shell
Check the location of the virtual environment - pipenv --venv
Deactivate the virtual environment = exit
Running a command in the environment (note that the virtual environment need not be activated for this) - pipenv run <command>
. Ex: pipenv run python
or pipenv run python my_script.py
Installing packages from requirements.txt
- pipenv install -r requirements.txt
Viewing installed packages and dependencies - pipenv lock -r
Installing dev dependencies - pipenv install <package> --dev
. Ex: pipenv install pytest --dev
Uninstall a package - pipenv uninstall <package>
. Ex: pipenv uninstall requests
Recreate virtual environment after updating the Python version in pipfile
- pipenv --python <version>
. Ex: pipenv --python 3.8
. This will recreate the virtual environment.
Remove a virtual environment - pipenv --rm
Create a new virtual environment from the pipfile
- pipenv install
Check for known security vulnerabilities in the installed packages - pipenv check
View dependency graph for installed packages - pipenv graph
Update pipfile.lock
- pipenv lock
Install packages from pipfile.lock
- pipenv install --ignore-pipfile
export PIPENV_VENV_IN_PROJECT="enabled"
Another way is to create a folder named .venv
in the project root and run pipenv --python <version>
. This will use .venv
as the virtual environment.