In this article I am will share some basic tools I recommend to use with every python project.
Pyenv
The first tool in my daily toolbox is pyenv. Pyenv allows to install and manage multiple python environments at the same time.
Key benefits:
- you can install any python version available in pypi at your machine
- time saving: you do not need to care about the installation process, pyevn will do everything for you
- manages virtualenvironments- it is a single tool to add manage both the python version as well as the virtualenvironments.
How to install
To install the main package run
brew install pyenv
and the the virtualenv manager
brew install pyenv-virtualenv
Add to ~/.bash_profile
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
The useful commands
List all available python versions
pyenv install --list
Install specific python version (the python will be installed in ~/.pyenv/versions)
pyenv install 3.5.5
Uninstall python version
pyenv uninstall 2.7.15
Show commands
pyenv commands
Show all installed versions
pyenv versions
Show current active version
pyenv version
Show the full path to the binary
pyenv which pip
Set local python version (creates .python-version)
pyenv local 3.4.5
VIrtualenv Create a virtualenv
pyenv virtualenv 3.5.5 project1
Activate an environment
pyenv virtualenv 3.5.5 project1
cd project1
# will activate the virtualenv (if you cd out of the project dir virtualenv will be different)
pyenv local project1
Activate the environment
pyenv activate venv
Deactivate the environment
pyenv deactivate venv
List the virtual environments
pyenv virtualenvs
To see which pip is used
pyenv which pip