- Install multiple versions of python
python
usingasdf
(orpyenv
) - Install
pipenv
for all versions - Optional: Install global pip packages for the default version of python
TOOCS - The Opinionated One-Click Setups are a set of tools / ansible roles designed to setup a system in one click. They are a simple, reliable, way to setup a given tool. You can use them as is, or, inspecting their code, as a tutorial to follow step by step.
They are, as their name suggests, opinionated: while they guarantee to setup the given tool in one click, they do not guarantee consistency in how they achieve it, new releases might introduce breaking changes.
Read the code and make sure you understand what's happening!
This role is only working on MacOSX & Ubuntu/Debian.
-
- List of python version to install
- The order in which they are listed will be the order in why they will be prioritized
Learn more about it: List of versions to install is ordered - Required
-
- List of pip packages to install
- The packages will only be installed for the default version of python (the first in the list)
- Default:
[]
-
- Valid values:
asdf
,pyenv
- See Installation Methods
- Default:
asdf
- Valid values:
-
- Skip the shell setup when installing
asdf
- See Installation Methods
- Default:
False
- Skip the shell setup when installing
Prefered and default installation method using the asdf
version manager
The installation and configuration of asdf
as well as the python installation is delegated to another TOOCS: TOOCS.asdf.
This TOOCS only takes care of installing the optional global pip modules.
-
If you are using
zsh
, you're all set! Your shell has been automatically set up during the installation ofasdf
. -
If you are NOT using
zsh
some manual setup is required, see: TOOCS/asdf - Nonzsh
Users -
Alternatively, if
asdf
is already setup on your machine, you might want to skip theasdf
automatic shell setup => Set the variableasdf_skip_shell_setup
toTrue
Alternative version using the pyenv
version manager
Since pyenv
is used to manage the different python
versions, it needs to be activated in your shell.
Simply add these lines to the corresponding files:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
The reason we're splitting the initialisation between these two files is to ensure smooth operation with both pyenv
and pipenv
. That way, the pyenv
activation is only done once per login shell and does not interfere with the sub-shell started with pipenv shell
.
Learn more about it: Pyenv Issue #184 - Wrong Python inside of 'pipenv shell'
- 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
MIT
Follow me on Twitter: @ThisIsFlorianK
Find out more about my work: Florian Kempenich - Personal Website