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 = /Users/lberton/.ansible/collections:/usr/share/ansible/collections
executable location = /opt/homebrew/bin/ansible
python version = 3.12.0 (main, Oct 2 2023, 12:03:24) [Clang 15.0.0 (clang-1500.0.40.1)] (/opt/homebrew/Cellar/ansible/8.6.1/libexec/bin/python)
jinja version = 3.1.2
libyaml = True

Step 1: Identify the Problem

The error message indicates that the ‘markupsafe’ module is not found. This module is a dependency for Ansible and needs to be installed.

Step 2: Check for ‘markupsafe’ Installation

First, let’s check if the ‘markupsafe’ module is installed. Open your terminal and run:

python3.12 -m pip show markupsafe

If the module is not installed, you will need to install it. If it’s already installed, proceed to the next step.

The Best Resources For Ansible

--

--

Luca Berton

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