nasa/fprime-tools

ImportError with MarkupSafe version 2.1.1

Closed this issue · 2 comments

F´ Version v3.0.1
Affected Component

Problem Description

fprime-util encounters ImportError with MarkupSafe version 2.1.1

$ fprime-util --help
Traceback (most recent call last):
  File "/usr/local/bin/fprime-util", line 5, in <module>
    from fprime.util.__main__ import main
  File "/usr/local/lib/python3.8/dist-packages/fprime/util/__main__.py", line 9, in <module>
    import fprime.util.build_helper
  File "/usr/local/lib/python3.8/dist-packages/fprime/util/build_helper.py", line 31, in <module>
    from fprime.fbuild.cli import add_fbuild_parsers, get_target
  File "/usr/local/lib/python3.8/dist-packages/fprime/fbuild/cli.py", line 12, in <module>
    from fprime.fbuild.interaction import confirm
  File "/usr/local/lib/python3.8/dist-packages/fprime/fbuild/interaction.py", line 12, in <module>
    from cookiecutter.main import cookiecutter
  File "/usr/local/lib/python3.8/dist-packages/cookiecutter/main.py", line 15, in <module>
    from cookiecutter.generate import generate_context, generate_files
  File "/usr/local/lib/python3.8/dist-packages/cookiecutter/generate.py", line 15, in <module>
    from jinja2 import FileSystemLoader
  File "/usr/lib/python3/dist-packages/jinja2/__init__.py", line 33, in <module>
    from jinja2.environment import Environment, Template
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 15, in <module>
    from jinja2 import nodes
  File "/usr/lib/python3/dist-packages/jinja2/nodes.py", line 23, in <module>
    from jinja2.utils import Markup
  File "/usr/lib/python3/dist-packages/jinja2/utils.py", line 656, in <module>
    from markupsafe import Markup, escape, soft_unicode
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/usr/local/lib/python3.8/dist-packages/markupsafe/__init__.py)

How to Reproduce

  1. pip install fprime-tools
  2. fprime-util --help

Expected Behavior

Should display help text

Pinning MarkupSafe to version 2.0.1 seems to have fixed the issue

The root cause of your issue may stem from a dependency management conflict between two software ecosystems. According to the error message, your 'markupsafe' was installed using 'pip' at the path /usr/local/lib/python3.8/dist-packages/markupsafe. The 'jinja2' that depends on it was installed using 'apt' at the path /usr/lib/python3/dist-packages/jinja2. The versions of the two are not compatible. In fact, there is a version of 'markupsafe' in the system that 'jinja2' correctly depends on, but the Python interpreter prioritizes the 'markupsafe' installed by 'pip', leading to this issue. There are typically two solutions to this problem: (1) Use 'pip' to uninstall markupsafe, and then reinstall it using 'apt', or uninstall 'jinja2' using 'apt' and reinstall it using 'pip'. (2) Use Python's imp module to customize the path and import the 'markupsafe' from the 'apt' path before importing 'jinja2'. An example is as follows:

import imp
path = ['/usr/lib/python3/dist-packages']
fp, pathname, description = imp.find_module('markupsafe', path)
imp.load_module("markupsafe", fp, pathname, description)

Hope my diagnosis is helpful to you! @capsulecorplab