Pipenv
Table of contents
Advantage to venv
Pipenv’s Pipfile serves as an upgrade to requirements.txt.
It allows you to separately mark production and development dependencies.
Basic usage
Install
brew install pipenv
Create environment and install
Go to the desired project folder. To create and use a virtual environment for this root:
pipenv
pipenv install <package-name> # Install specific package
If there’s already a Pipfile, create env and install listed requirements:
pipenv install # With Pipfile
All the pipenv environments are in ~/.local/share/virtualenvs/root-dir-name-hash/ by default.
Activate and deactivate environment
Activate
pipenv shell
Deactivate
exit
Do not use deactivate.
Create Pipfile.lock
pipenv lock
Delete environment
To delete the environment for current directory:
pipenv --rm
Use pipenv with a specific Python version
You can set a specific version of Python when creating a pipenv virtual environment.
pipenv --python 3.x
However, it requires that Python 3.x is already installed on your local machine unlike conda create -n myenv python=3.x.
You can either,
- (Not recommended)
brew installthe desired Python 3.x - (Recommended) Use pyenv
- (Meh..) Create a conda environment with the desired version and only use the binary
Then navigate to the root of the project and make Pipenv use the active Python:
pipenv --python=$(which python) --site-packages # Creates an env in cwd
pipenv run which python # It will point to a binary in `~/.local/share/virtualenvs/some-root-dir-hash/bin/python`
pipenv run python -V # Check that it is indeed 3.x