diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index c0f0608f1ab32..ab5e9cabfa099 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -6,6 +6,7 @@ Sequence, ) from functools import partial +import pathlib import re from typing import ( TYPE_CHECKING, @@ -71,7 +72,9 @@ class StylerRenderer: Base class to process rendering a Styler with a specified jinja2 template. """ - loader = jinja2.PackageLoader("pandas", "io/formats/templates") + thisdir = pathlib.Path(__file__).parent.resolve() + template_dir = thisdir / "templates" + loader = jinja2.FileSystemLoader(template_dir) env = jinja2.Environment(loader=loader, trim_blocks=True) template_html = env.get_template("html.tpl") template_html_table = env.get_template("html_table.tpl") diff --git a/pandas/tests/io/formats/style/test_html.py b/pandas/tests/io/formats/style/test_html.py index 752b9b391f9cb..e46a59197a3b7 100644 --- a/pandas/tests/io/formats/style/test_html.py +++ b/pandas/tests/io/formats/style/test_html.py @@ -1,3 +1,4 @@ +import pathlib from textwrap import ( dedent, indent, @@ -18,7 +19,9 @@ @pytest.fixture def env(): - loader = jinja2.PackageLoader("pandas", "io/formats/templates") + project_dir = pathlib.Path(__file__).parent.parent.parent.parent.parent.resolve() + template_dir = project_dir / "io" / "formats" / "templates" + loader = jinja2.FileSystemLoader(template_dir) env = jinja2.Environment(loader=loader, trim_blocks=True) return env