-
pipenv
is a virtual environment creating tool(likevenv
), which ships with its own package manager(likepip
). -
It is similar to
conda
(Anaconda), cz it creates environment related files in a default location (for example,/home/<user_name>/.local/share/virtualenvs/
in Unix). But the latter is used in Data Science and ML. -
It creates Pipfile(TOML) and Pipfile.lock(JSON) files. The former is like a replacement to requirements.txt. The latter is for consistent and deterministic builds, mostly for other developers to install the exact versions.
-
pipenv
automatically identifies files like .env, requirements.txt, .flaskenv etc.
# Run this as Administrator
pip install pipenv
sudo pip3 install pipenv
This command creates and activates the virtual environment if doesn't already exists, and just enables/activates it if it already exits.
pipenv shell
- This command exits or deactivates the virtual environment.
exit
# Or press Ctrl+D
- This command deletes the virtual environment, but leaves the Pipfile and Pipfile.lock files.
pipenv --rm
# 1) To enter into REPL
# a) Windows
python
# b) Unix
python3
# 2) Check
>>> import sys
>>> sys.executable
>>> quit()
:: Command Prompt
where python
# PowerShell
Get-Command python
which python
NOTES :
- To check where the virtual environment files are located :
pipenv --venv
- To check where the project home is located :
pipenv --where
# Install flask
pipenv install flask
# Uninstall flask
pipenv uninstall flask
# Install as develop packages
pipenv install autopep8 flake8 --dev
# Uninstall the develop packages
pipenv uninstall autopep8 flake8 --dev
This assumes you have the Pipfile.lock and Pipfile files.
# Install all default packages from Pipfile
pipenv install
# Install all default and develop packages from Pipfile
pipenv install --dev
NOTE : To re-install the virtual environment with a specific version of Python :
# Perform it after updating the python version in Pipfile as 3.6
pipenv install --python 3.6
# Or
pipenv --python 3.6
# Perform it if you want to install all packages with Python2
pipenv install --two
# Perform it if you want to install all packages with Python3
pipenv install --three
# Uninstall all default packages
pipenv uninstall --all
# Uninstall all develop packages
pipenv uninstall --all-dev
pipenv update
runs both pipenv lock
and pipenv sync
pipenv update flask
pipenv update
NOTE :
What is
pipenv sync
?
- It is similar to
pipenv install --ignore-pipfile
, but doesn't re-lock the dependencies.- It installs the exact versions as in Pipfile.lock.
Gives a tree-like structure of all the dependencies and thier dependencies
pipenv graph
pipenv
by default installs packages from a requirements.txt file, if it exists.- We can explicitly ask it to do so, too.
# Install packages from a requirements.txt file
pipenv install -r requirements.txt
# Install develop packages from a dev-requirements.txt file
pipenv install -r dev-requirements.txt --dev
# Create a requirements.txt for packages
pipenv lock -r > requirements.txt
# Create a dev-requirements.txt for develop packages
pipenv lock -r -d > dev-requirements.txt
- This will take a snapshot of all the packages with exact versions
- Similar to
pip freeze
pipenv lock
- You don't want to install packages based on a Pipfile.
- One should always depend on Pipfile.lock as it is precise and exact.
pipenv install --ignore-pipfile
Use this command to see any vulnerable security issues. If exists, update the Pipfile manually.
pipenv check
pipenv run <any_command>