ModuleNotFoundError: No module named ‘jinja2’ python

Hi All

I am not able to use jinja2 in my python code getting below error:

Executing the Python script failed: Traceback (most recent call last):
File “”, line 3, in
ModuleNotFoundError: No module named ‘jinja2’

I have already installed this and below is the version not sure why I am still getting this error, any suggestion would be really helpful for me

(base) C:\Users\a-mmj>pip show jinja2

Name: Jinja2

Version: 3.1.2

Summary: A very fast and expressive template engine.

Home-page: Jinja | The Pallets Projects

Author: Armin Ronacher

Author-email: armin.ronacher@active-4.com

License: BSD-3-Clause

Location: C:\Users\a-mmj\AppData\Local\anaconda3\Lib\site-packages

Requires: MarkupSafe

Required-by: anaconda-project, bokeh, conda-build, conda-verify, conda_index, cookiecutter, distributed, Flask, intake, jinja2-time, jupyter-server, jupyterlab, jupyterlab_server, nbclassic, nbconvert, notebook, numpydoc, Sphinx

Thank you

Hi @madhumita3,

you are saying that you have jinja2 installed via pip already.
According to this line

(base) C:\Users\a-mmj>pip show jinja2

you have installed it in the base environment.
Please check which environment you use for your Python Script node (in the KNIME Analytics Platform via Preferences -> KNIME -> Python). If the radio button is set to bundled, you need to create a new environment like this in your terminal:

conda create --name my_python_env -c knime -c conda-forge knime-python-scripting=5.2 python=3.11

Then you can

conda activate my_python_env

and

pip install jinja2

Then in the preferences, select that environment.

That way, you

  1. ensure that you have a Python environment, which has the packages necessary for KNIME (knime-python-scripting) and your pip packages (jinja2) and
  2. ensure that the Python Script nodes use exactly that environment

Does that help?
Steffen

4 Likes

Thank you Steffen for your solution and it worked for me.

1 Like

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