Specifying Python3 on Ansible Target Hosts to Run pip install
Overview
On a Raspberry Pi Zero WH, running python -V returned Python 2.7.16.
The Raspberry Pi setup is managed with Ansible, so I was wondering whether I shouldunlink python and ln -s /usr/bin/python3 /usr/bin/python via Ansible.
But it turned out there was a much simpler way, so here’s a quick note.
OS Version Information
1 | $ cat /etc/os-release |
The Thumbnail Says It All, but Just in Case
The following ansible.cfg setting is all there is to it.
- ansible.cfg
1 | [defaults] |
- tasks/main.yml
1 | # NOTE: use it as pip3 |
After running ansible-playbook:
1 | // python2 is linked to /usr/bin/python |
Without bothering to switch the linked python, I was able to simply specify the Python version and use it!
That’s all.
I hope this is helpful.

