Skip to content

Instantly share code, notes, and snippets.

@AbhishekPednekar84
Last active April 12, 2022 06:17
Show Gist options
  • Save AbhishekPednekar84/47586ae33becb1b70c98ac4fbc629acc to your computer and use it in GitHub Desktop.
Save AbhishekPednekar84/47586ae33becb1b70c98ac4fbc629acc to your computer and use it in GitHub Desktop.

Useful pipenv commands

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

Creating a virtual environment in the current folder

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment