Ansible troubleshooting — ERROR: No module named ‘markupsafe’

How to Solve the “ERROR: No module named markupsafe” Issue after Upgrading Python 3.12 on Mac with Homebrew

Luca Berton

--

Introduction

After upgrading Python to version 3.12 on your Mac using Homebrew, you encountered an error when trying to run Ansible: “ERROR: No module named 'markupsafe'”. This issue arises because Ansible relies on certain Python modules, and in this case, it seems that the ‘markupsafe’ module is missing or not properly installed.

Let’s go through the steps to resolve this issue:

ERROR: No module named 'markupsafe'

DL;DR

$ ansible
ERROR: No module named 'markupsafe'
$ brew uninstall ansible-lint ansible python-markupsafe
$ brew install ansible-lint ansible python-markupsafe
$ ansible --version
ansible [core 2.15.6]
config file = None
configured module search path = ['/Users/lberton/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /opt/homebrew/Cellar/ansible/8.6.1/libexec/lib/python3.12/site-packages/ansible
ansible collection location =…

--

--

Luca Berton

I help creative Automation DevOps, Cloud Engineer, System Administrator, and IT Professional to succeed with Ansible Technology to automate more things everyday