Pipenv Cheatsheet

1 minute read

Introduction

Pipenv uses pip for package management and virtualenv for maintaining virtual environment under the hood. It works as a wrapper and uses same kind of syntax to make it easy to work.

You can more or less forget about using pip and virtualenv if you are using pipenv.

pip install pipenv

Cheatsheet

Activate/Deactivate Environment

pipenv shell// Activate

exit// Deactivate

Locate environment

pipenv –venv // locates for a particular project

Delete environment

pipenv –rm// This will not remove the Pipfiles

Install/Uninstall/Update Packages

pipenv install flask// If virtual environment doesn’t exist, it’ll create it

pipenv install flask==0.12.1// Installs specific version

pipenv install pytest –dev// To separate dev packages from production environment


pipenv uninstall flask// Uninstalls package

pipenv uninstall –all// Uninstalls all packages

pipenv uninstall –all-dev// Uninstalls all dev packages


pipenv update package_name // Update specific package

pipenv update// Updates all packages

Create/Update the lock file

pipenv lock // Done usually before pushing the code

To install from Pipfile

pipenv install –dev // installs from pipfile along with dev pacakges; creates environment if not present; updates packages if version not mentioned

pipenv install // doesn’t install dev packages; creates environment if not present; updates packages if version not mentioned

pipenv install –ignore-pipfile // installs from lock file; ccreates environment if not present; updates packages if version not mentioned

Extra Features

Install/Export requirements.txt

pipenv install -r requirements.txt // installs a list of requirements

pipenv lock -r > requirements.txt // export a list of requirements

Create environment with specific python version

pipenv shell –python 3.5 // will use python 3.5 now

Open Third Party Package

pipenv open requests // opens code in default editor; to open in vscode use environment variable EDITOR=code

Run in Environment without opening Shell

pipenv run </span>   // e.g pipenv run python app.py

Check Security Vulnerabilities

pipenv check

List Packages and their Dependencies

pipenv graph// to resolve conflicting sub-dependencies use pipenv graph --reverse

Updated: