TOOCS.python
TOOCS / Ansible Role: TOOCS.python
/!\ This role has been renamed - Old name:
FlorianKempenich.python-virtualenv
/!\
- Install multiple Python versions using
asdf
(orpyenv
) - Install
pipenv
for all versions - Optionally, install global pip packages for the default Python version
What is TOOCS?
TOOCS - The Opinionated One-Click Setups is a set of tools/Ansible roles designed to set up a system quickly. They provide a simple and reliable way to install a specific tool. You can use them directly, or inspect the code as a step-by-step tutorial.
They are "opinionated," meaning they ensure the tool is set up quickly but do not guarantee consistency in how it's done. New updates might introduce changes that could break things.
Review the code to understand what it does!
Requirements
This role works only on MacOS and Ubuntu/Debian.
Role Variables
python_versions
- List of Python versions to install
- The order listed is the priority order
Learn more: Versions to install are ordered - Required
global_pip_packages
- List of pip packages to install
- Packages will only be installed for the default Python version (the first one in the list)
- Default:
[]
installation_method
- Valid values:
asdf
,pyenv
- See Installation Methods
- Default:
asdf
- Valid values:
asdf_skip_shell_setup
- Skip shell setup when installing
asdf
- See Installation Methods
- Default:
False
- Skip shell setup when installing
Installation Methods
asdf
This is the preferred and default installation method using the asdf
version manager.
The installation and configuration of asdf
, as well as Python installation, is handled by another TOOCS: TOOCS.asdf.
This TOOCS only installs the optional global pip packages.
Post-install - with asdf
: Shell configuration
Using
zsh
? You're all set! Your shell is automatically configured duringasdf
installation.Not using
zsh
? Manual setup is needed: TOOCS/asdf - Nonzsh
UsersIf
asdf
is already set up on your computer, you can skip automatic shell setup by settingasdf_skip_shell_setup
toTrue
.
pyenv
An alternative method using the pyenv
version manager.
Post-install - with pyenv
: Shell configuration
Since pyenv
manages different Python versions, it must be activated in your shell.
Add these lines to the appropriate files:
~/.zshrc
or~/.bashrc
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
~/.zlogin
or~/.bash_profile
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
The split initialization helps avoid problems with both pyenv
and pipenv
. This way, pyenv
activation happens once per login shell and doesn't interfere with pipenv shell
.
Learn more: Pyenv Issue #184 - Wrong Python inside of 'pipenv shell'
Example Playbook
- hosts: localhost
tasks:
- include_role:
name: TOOCS.python
vars:
python_versions:
- 3.7.0
- 2.7.15
global_pip_packages:
- cheat
- howdoi
- ansible-droplet
# OR
- hosts: localhost
tasks:
- include_role:
name: TOOCS.python
vars:
python_versions:
- 3.7.0
installation_method: asdf
asdf_skip_shell_setup: True
# OR
- hosts: localhost
tasks:
- include_role:
name: TOOCS.python
vars:
python_versions:
- 3.7.0
installation_method: pyenv
License
MIT
Author Information
Follow me on Twitter: @ThisIsFlorianK
Learn more about my work: Florian Kempenich - Personal Website
Install multiple versions of Python with some optional global packages
ansible-galaxy install TOOCS.python