Repository: pyinstaller/pyinstaller

Issue:
After  converting  .py to .exe using pyinstaller and running the .py file I am getting this error.
[548 rows x 83 columns]]
83 83 83
Traceback (most recent call last):
  File "UserInterface.py", line 1846, in export
  File "UserInterface.py", line 1559, in summaryReport
  File "pandas\core\frame.py", line 1151, in style
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "pandas\io\formats\style.py", line 51, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "pandas\io\formats\style_render.py", line 62, in <module>
  File "pandas\io\formats\style_render.py", line 67, in StylerRenderer
  File "jinja2\loaders.py", line 310, in __init__
ValueError: The 'pandas' package was not installed in a way that PackageLoader understands.



----------------------------------------------------------------------------------------------------------------------------------
![Screenshot (85)](https://user-images.githubusercontent.com/31065924/125654737-01dcda63-2c8f-4aa1-988c-bd28550c67a5.png)



Discussion:
I think that's caused by missing data; try adding `--hiddenimport jinja2 --collect-data "pandas.io.formats"` to your pyinstaller command-line.

Resolving patch:
diff --git a/PyInstaller/hooks/hook-pandas.io.formats.style.py b/PyInstaller/hooks/hook-pandas.io.formats.style.py
new file mode 100644
--- /dev/null
+++ b/PyInstaller/hooks/hook-pandas.io.formats.style.py
@@ -0,0 +1,18 @@
+#-----------------------------------------------------------------------------
+# Copyright (c) 2021, PyInstaller Development Team.
+#
+# Distributed under the terms of the GNU General Public License (version 2
+# or later) with exception for distributing the bootloader.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+#
+# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
+#-----------------------------------------------------------------------------
+
+from PyInstaller.utils.hooks import collect_data_files
+
+# This module indirectly imports jinja2
+hiddenimports = ['jinja2']
+
+# It also requires template file stored in pandas/io/formats/templates
+datas = collect_data_files('pandas.io.formats')


Test patch:
diff --git a/tests/functional/test_libraries.py b/tests/functional/test_libraries.py
--- a/tests/functional/test_libraries.py
+++ b/tests/functional/test_libraries.py
@@ -391,6 +391,18 @@ def test_pandas_extension(pyi_builder):
         """)
 
 
+@importorskip('pandas')
+@importorskip('jinja2')
+def test_pandas_io_formats_style(pyi_builder):
+    # pandas.io.formats.style requires jinja2 as hiddenimport, as
+    # well as collected template file from pandas/io/formats/templates.
+    # See #6008 and #6009.
+    pyi_builder.test_source(
+        """
+        import pandas.io.formats.style
+        """)
+
+
 @importorskip('win32ctypes')
 @pytest.mark.skipif(not is_win,
                     reason='pywin32-ctypes is supported only on Windows')