Create a tools virtual environment using pyenv, to install tools like pipx and other Python utilities.:

pyenv virtualenv tools

if need a special Python version, use:

pyenv virtualenv 3.13.5 tools

Activate the tools virtual environment:

pyenv activate tools

Install pipx in the tools virtual environment:

pip install pipx

Now run the pipx ensurepath command to ensure that the pipx binary is in your PATH:

pipx ensurepath

Normally the path is $HOME/.local/bin, and the apps will be simlinked there.

Now install ansible using pipx:

pipx install ansible

Or a specicfic version of Ansible, like for example to cover this problem: SyntaxError: future feature annotations is not defined:

pipx install ansible-core==2.16.8
pipx inject ansible-core passlib

You can now deactivate the tools virtual environment:

pyenv deactivate

Then for example to install ansible collections, you can use:

ansible-galaxy collection install ansible.posix
ansible-galaxy collection install ansible.utils
ansible-galaxy collection install community.crypto
ansible-galaxy collection install community.general
ansible-galaxy collection install community.hashi_vault
ansible-galaxy collection install community.mysql
ansible-galaxy collection install community.postgresql

To list the installed collections, you can use:

ansible-galaxy collection list