aegirhall / console-menu

A simple Python menu system for building terminal user interfaces.
MIT License
365 stars 58 forks source link

Textwrap3 import issue with pyinstaller #66

Closed hassankhalid55 closed 2 years ago

hassankhalid55 commented 2 years ago

Hi,

I am getting the following import error while trying to create a standalone executable of my project using pyinstaller. I have already tried specifying the textwrap3 (dependency used by console menu) as a hidden import in a hook file for console menu, but it is not working.

Traceback (most recent call last): File "main.py", line 4, in <module> File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "consolemenu\__init__.py", line 1, in <module> File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "consolemenu\items\__init__.py", line 1, in <module> File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "consolemenu\console_menu.py", line 9, in <module> File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "consolemenu\menu_formatter.py", line 3, in <module> File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "consolemenu\menu_component.py", line 1, in <module> File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "ansiwrap\__init__.py", line 1, in <module> File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "ansiwrap\core.py", line 11, in <module> File "imp.py", line 296, in find_module ImportError: No module named 'textwrap3' [34192] Failed to execute script 'main' due to unhandled exception!

Using this command to create a standalone exe, pyinstaller -n TextFileConversionUtility main.py --onefile --additional-hooks-dir=./hooks

gustavobsch commented 2 years ago

+1. having the same issue

stefanoandreozzi commented 2 years ago

+1. same for me

aegirhall commented 2 years ago

This issue is actually caused by the ansiwrap package (issue #6). However, console-menu v0.7.1 provides a workaround, to fall back to textwrap if the ansiwrap import fails. The unfortunate downside to this is that ansi colors will no longer wrap properly when using PyInstaller. (Non PyInstaller environments will continue working properly.) When/if ansiwrap provides a proper fix, this workaround can be removed.