Error running pytest -m projection. Cannot find 'Markup' in Jinja2

Hello all.

I am having trouble running this test in the “Ticket: projection” stage of the course.
I am running the correct python version for the requirements.txt, and have confirmed that I have the version of Jinja2 that the requirements.txt specifies, so at a loss as to why the “Markup” entries in the Jinja2 package are missing.

(mflix-python) PS C:\coding\mflix> pytest -m projection
Traceback (most recent call last):
  File "C:\Users\brann\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\brann\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\coding\mflix\mflix-python\Scripts\pytest.exe\__main__.py", line 7, in <module>
  File "C:\coding\mflix\mflix-python\lib\site-packages\_pytest\config.py", line 50, in main
    config = _prepareconfig(args, plugins)
    return pluginmanager.hook.pytest_cmdline_parse(
  File "C:\coding\mflix\mflix-python\lib\site-packages\pluggy\__init__.py", line 617, in __call__
  File "C:\coding\mflix\mflix-python\lib\site-packages\pluggy\__init__.py", line 222, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "C:\coding\mflix\mflix-python\lib\site-packages\pluggy\__init__.py", line 214, in <lambda>
    hook.multicall(
  File "C:\coding\mflix\mflix-python\lib\site-packages\pluggy\callers.py", line 196, in _multicall
    gen.send(outcome)
  File "C:\coding\mflix\mflix-python\lib\site-packages\_pytest\helpconfig.py", line 68, in pytest_cmdline_parse
    config = outcome.get_result()
  File "C:\coding\mflix\mflix-python\lib\site-packages\pluggy\callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "C:\coding\mflix\mflix-python\lib\site-packages\pluggy\callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "C:\coding\mflix\mflix-python\lib\site-packages\_pytest\config.py", line 942, in pytest_cmdline_parse
    self.parse(args)
  File "C:\coding\mflix\mflix-python\lib\site-packages\_pytest\config.py", line 1107, in parse
    self._preparse(args, addopts=addopts)
  File "C:\coding\mflix\mflix-python\lib\site-packages\_pytest\config.py", line 1070, in _preparse
    self.pluginmanager.load_setuptools_entrypoints('pytest11')
  File "C:\coding\mflix\mflix-python\lib\site-packages\pluggy\__init__.py", line 397, in load_setuptools_entrypoints
    plugin = ep.load()
  File "C:\coding\mflix\mflix-python\lib\site-packages\pkg_resources\__init__.py", line 2471, in load
    return self.resolve()
  File "C:\coding\mflix\mflix-python\lib\site-packages\pkg_resources\__init__.py", line 2477, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "C:\coding\mflix\mflix-python\lib\site-packages\_pytest\assertion\rewrite.py", line 212, in load_module
    py.builtin.exec_(co, mod.__dict__)
  File "C:\coding\mflix\mflix-python\lib\site-packages\pytest_flask\plugin.py", line 11, in <module>
    from flask import json
  File "C:\coding\mflix\mflix-python\lib\site-packages\flask\__init__.py", line 19, in <module>
    from jinja2 import Markup, escape
ImportError: cannot import name 'Markup' from 'jinja2' (C:\coding\mflix\mflix-python\lib\site-packages\jinja2\__init__.py)
(mflix-python) PS C:\coding\mflix> pip install -U Jinja2
Requirement already satisfied: Jinja2 in c:\coding\mflix\mflix-python\lib\site-packages (3.1.2)
Requirement already satisfied: MarkupSafe>=2.0 in c:\coding\mflix\mflix-python\lib\site-packages (from Jinja2) (2.1.1)
(mflix-python) PS C:\coding\mflix> pytest -m projection
Traceback (most recent call last):
  File "C:\Users\brann\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\brann\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\coding\mflix\mflix-python\Scripts\pytest.exe\__main__.py", line 7, in <module>
  File "C:\coding\mflix\mflix-python\lib\site-packages\_pytest\config.py", line 50, in main
    config = _prepareconfig(args, plugins)
    return pluginmanager.hook.pytest_cmdline_parse(
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "C:\coding\mflix\mflix-python\lib\site-packages\pluggy\__init__.py", line 222, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "C:\coding\mflix\mflix-python\lib\site-packages\pluggy\__init__.py", line 214, in <lambda>
    hook.multicall(
  File "C:\coding\mflix\mflix-python\lib\site-packages\pluggy\callers.py", line 196, in _multicall
    gen.send(outcome)
  File "C:\coding\mflix\mflix-python\lib\site-packages\_pytest\helpconfig.py", line 68, in pytest_cmdline_parse
    config = outcome.get_result()
  File "C:\coding\mflix\mflix-python\lib\site-packages\pluggy\callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "C:\coding\mflix\mflix-python\lib\site-packages\pluggy\callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "C:\coding\mflix\mflix-python\lib\site-packages\_pytest\config.py", line 942, in pytest_cmdline_parse
    self.parse(args)
  File "C:\coding\mflix\mflix-python\lib\site-packages\_pytest\config.py", line 1107, in parse
    self._preparse(args, addopts=addopts)
  File "C:\coding\mflix\mflix-python\lib\site-packages\_pytest\config.py", line 1070, in _preparse
    self.pluginmanager.load_setuptools_entrypoints('pytest11')
  File "C:\coding\mflix\mflix-python\lib\site-packages\pluggy\__init__.py", line 397, in load_setuptools_entrypoints
    plugin = ep.load()
  File "C:\coding\mflix\mflix-python\lib\site-packages\pkg_resources\__init__.py", line 2471, in load
    return self.resolve()
  File "C:\coding\mflix\mflix-python\lib\site-packages\pkg_resources\__init__.py", line 2477, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "C:\coding\mflix\mflix-python\lib\site-packages\_pytest\assertion\rewrite.py", line 212, in load_module
    py.builtin.exec_(co, mod.__dict__)
  File "C:\coding\mflix\mflix-python\lib\site-packages\pytest_flask\plugin.py", line 11, in <module>
    from flask import json
  File "C:\coding\mflix\mflix-python\lib\site-packages\flask\__init__.py", line 19, in <module>
    from jinja2 import Markup, escape
ImportError: cannot import name 'Markup' from 'jinja2' (C:\coding\mflix\mflix-python\lib\site-packages\jinja2\__init__.py)
(mflix-python) PS C:\coding\mflix> python --version
Python 3.8.10
(mflix-python) PS C:\coding\mflix> pip install -U Jinja2
Requirement already satisfied: Jinja2 in c:\coding\mflix\mflix-python\lib\site-packages (3.1.2)
Requirement already satisfied: MarkupSafe>=2.0 in c:\coding\mflix\mflix-python\lib\site-packages (from Jinja2) (2.1.1)

I have attached the error message I am getting. If anyone can help, I would greatly appreciate it.

Thanks for your time.
Kenneth

Hey @kenny_bb,

Welcome to the MongoDB Community Forums! :leaves:

Which version of Jinja2 and flask are you using? The recommended ones are listed in the requirements.txt file. Kindly make sure you are using those versions only. I was just reading that some of Jinja’s internal modules were changed in a recent release and that may be one of the reasons that you are encountering this error if you are on the latest version.

Let us know if the problem still persists. Please feel free to reach out for anything else as well.

Regards,
Satyam

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.