saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:

Home Page:https://repo.saltproject.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ImportError: cannot import name 'Markup' from 'jinja2'

babunatarajan opened this issue · comments

Description of Issue

ImportError: cannot import name 'Markup' from 'jinja2' (/usr/local/lib/python3.8/dist-packages/jinja2/init.py)

Setup

OS
Ubuntu 20.04.4 LTS

salt-minion --version
salt-minion 3004.1

python3 --version
Python 3.8.10

pip3 freeze | egrep 'Jinja|Markup'
Jinja2==3.1.2
MarkupSafe==2.1.1

Steps to Reproduce Issue

sudo curl -fsSL -o /usr/share/keyrings/salt-archive-keyring.gpg https://repo.saltproject.io/py3/ubuntu/20.04/amd64/latest/salt-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/salt-archive-keyring.gpg arch=amd64] https://repo.saltproject.io/py3/ubuntu/20.04/amd64/latest focal main" | sudo tee /etc/apt/sources.list.d/salt.list
apt-get -y update
apt-get -y install salt-minion
service salt-minion restart

Workaround

vi /usr/lib/python3/dist-packages/salt/utils/jinja.py
Line 28
add from markupsafe import Markup
remove Markup from jinja2 import
from jinja2 import BaseLoader, TemplateNotFound, nodes

Line 709
Replace @jinja2.contextfunction with @jinja2.pass_context

Versions Report

Salt Version:
Salt: 3004.1

Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.7.3
docker-py: Not Installed
gitdb: 2.0.6
gitpython: 3.0.7
Jinja2: 2.10.1
libgit2: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 0.6.2
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: Not Installed
pycryptodome: 3.6.1
pygit2: Not Installed
Python: 3.8.10 (default, Mar 15 2022, 12:22:08)
python-gnupg: 0.4.5
PyYAML: 5.3.1
PyZMQ: 18.1.1
smmap: 2.0.5
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.2

System Versions:
dist: ubuntu 20.04 focal
locale: utf-8
machine: x86_64
release: 5.4.0-94-generic
system: Linux
version: Ubuntu 20.04 focal

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
If you have additional questions, email us at saltproject@vmware.com. We’re glad you’ve joined our community and look forward to doing awesome things with you!

Duplicate: #61848

Your versions report shows Jinja 2.10.1 (presumably the system package) but your pip freeze shows 3.1.2 (in /usr/local/lib/ according to the error message).

You need to ensure your Salt environment is consistent for all invocations, and avoid polluting the system Python installation with global pip installs.

To resolve this error, we need to import the ‘Markup’ from ‘markupsafe’ instead of ‘jinja2’. The other solution to this error is downgrading the Jinja2 module to a compatible version (3.0.3) or upgrading the flask to the latest version.

You can check this guide for a practical demonstration of resolving this error.