Essentially Pipenv is pip+virtualenv and it’s a match made in heaven. It manages dependencies, required python versions (if pyenv is available), generates pipfiles which is more reliable than a requirements.txt file and it generates a virtual environment so you don’t screw other environments and its requirements.
It automatically creates and manages a virtualenv for your projects, as well as adds/removes packages from your Pipfile as you install/uninstall packages. It also generates the ever–important Pipfile.lock, which is used to produce deterministic builds. — From Pipenv Repository
and it is officially recommended by Python.org:
While pip alone is often sufficient for personal use, Pipenv is recommended for collaborative projects as it’s a higher-level tool that simplifies dependency management for common use cases. — Python.org
Installation
Using pip
pip install --user pipenv
Create environment
Use argument --two or --three to specify the environment’s python version.
pipenv --three
Creating a virtualenv for this project… Using /home/franccesco/.pyenv/versions/3.6.4/bin/python3 to create virtualenv… ⠋Running virtualenv with interpreter /home/franccesco/.pyenv/versions/3.6.4/bin/python3
--SNIP --
Virtualenv location: /home/franccesco/.local/share/virtualenvs/test-PudGTmiz Creating a Pipfile for this project…
Install Dependencies
Let’s install requests as an example
pipenv install requests
Installing requests… Collecting requests
-- SNIP --
Adding requests to Pipfile's [packages]… PS: You have excellent taste! ✨ 🍰 ✨ Locking [dev-packages] dependencies… Locking [packages] dependencies… Updated Pipfile.lock (7b8df8)!
Managing environment
We can execute our python program without activating the virtual environment shell by running pipenv run python _pythonfile.py_ or accessing the virtual environment with pipenv shell
pipenv shell
Spawning environment shell (/usr/bin/fish). Use 'exit' to leave. source /home/franccesco/.local/share/virtualenvs/test-PudGTmiz/bin/activate.fish -- SNIP --