Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with Pytesseract #5641

Closed
gauthierbuttez opened this issue Mar 16, 2021 · 2 comments
Closed

Bug with Pytesseract #5641

gauthierbuttez opened this issue Mar 16, 2021 · 2 comments

Comments

@gauthierbuttez
Copy link

gauthierbuttez commented Mar 16, 2021

Hi,

I am trying to compile my Python 3.9 script with PyInstaller on my MAC OS Catalina:
MAC OS CATALINA 10.15.6
Python 3.9
Pyinstaller 4.2

When I run my python script from the terminal on my Mac, it runs fine without any issues.

I compiled with this command:

sudo python3 -m PyInstaller --uac-admin --windowed --icon=MyScript_icon.icns MyScript.spec 

here is MyScript.spec:

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['MyScript.py'],
             pathex=['/Users/alisa/Dropbox/cff/Python/MyScriptFolder'],
             binaries=[],
             datas=[( 'necessary_files/create_db.sql', '.'),
                    ( 'necessary_files/fra.traineddata', '.'),
                    ( 'ui.json', '.'),
                    ( 'MyScript_Install.sh', '.'),
                    ( 'necessary_files/assets', '.'),
                    ( 'necessary_files/selenium', '.'),
                    ( 'Start_MyScript.sh', '.'),
                    ( 'ui', 'ui' )],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=['FixTk', 'tcl', 'tk', '_tkinter', 'tkinter', 'Tkinter'],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='MyScript',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=False , uac_admin=True, icon='myscript_icon.icns')
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='MyScript')
app = BUNDLE(coll,
             name='MyScript.app',
             icon='MyScript_icon.icns',
             bundle_identifier=None)

When I double click on app, it doesn't launch the app. So I open it by command line:

open dist/MyScript.app/Contents/MacOS/MyScript 

A Terminal windows is showing up and a few seconds later this error message appears:

Traceback (most recent call last):
  File "MyScript.py", line 20, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 531, in exec_module
  File "prepare_envir_appium.py", line 20, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 531, in exec_module
  File "mymodules.py", line 46, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 531, in exec_module
  File "pytesseract/__init__.py", line 2, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 531, in exec_module
  File "pytesseract/pytesseract.py", line 40, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 531, in exec_module
  File "pandas/__init__.py", line 179, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 531, in exec_module
  File "pandas/testing.py", line 5, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 531, in exec_module
  File "pandas/_testing.py", line 29, in <module>
  File "pandas/_libs/testing.pyx", line 1, in init pandas._libs.testing
ModuleNotFoundError: No module named 'cmath'
[21640] Failed to execute script MyScript

So I search for installing cmath but I can't.
So I added it as hidden import in spec file but it didn't work.

This line 46 in mymodules.py is the importation of Tesseract Python module:

import pytesseract

So I tried to reproduce this issue with this minimal code:

import pytesseract

print("Hello")

and I get exact same issue!!! So there is a problem with PyInstaller compiling pytesseract?

Here are the log of pyinstaller compilation of minimum reproductable code:

132 INFO: PyInstaller: 4.2
132 INFO: Python: 3.9.2
159 INFO: Platform: macOS-10.15.7-x86_64-i386-64bit
161 INFO: wrote /Users/alisa/Dropbox/cff/Python/MyScriptFolder/test.spec
166 INFO: UPX is not available.
169 INFO: Extending PYTHONPATH with paths
['/Users/alisa/Dropbox/cff/Python/MyScriptFolder',
 '/Users/alisa/Dropbox/cff/Python/MyScriptFolder']
210 INFO: checking Analysis
210 INFO: Building Analysis because Analysis-00.toc is non existent
211 INFO: Initializing module dependency graph...
218 INFO: Caching module graph hooks...
237 WARNING: Several hooks defined for module 'win32ctypes.core'. Please take care they do not conflict.
241 INFO: Analyzing base_library.zip ...
3485 INFO: Processing pre-find module path hook distutils from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks/pre_find_module_path/hook-distutils.py'.
3488 INFO: distutils: retargeting to non-venv dir '/usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9'
7051 INFO: Processing pre-find module path hook site from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks/pre_find_module_path/hook-site.py'.
7052 INFO: site: retargeting to fake-dir '/usr/local/lib/python3.9/site-packages/PyInstaller/fake-modules'
15518 INFO: Processing pre-safe import module hook six.moves from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-six.moves.py'.
21593 INFO: Caching module dependency graph...
21895 INFO: running Analysis Analysis-00.toc
21905 INFO: Analyzing /Users/alisa/Dropbox/cff/Python/MyScriptFolder/test.py
21907 INFO: Processing module hooks...
21908 INFO: Loading module hook 'hook-pycparser.py' from '/usr/local/lib/python3.9/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
21909 INFO: Loading module hook 'hook-sqlite3.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
22019 INFO: Loading module hook 'hook-pkg_resources.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
22901 INFO: Processing pre-safe import module hook win32com from '/usr/local/lib/python3.9/site-packages/_pyinstaller_hooks_contrib/hooks/pre_safe_import_module/hook-win32com.py'.
22912 WARNING: Hidden import "pkg_resources.py2_warn" not found!
23218 WARNING: Hidden import "pkg_resources.markers" not found!
23221 INFO: Excluding import of __main__ from module pkg_resources
23222 INFO: Loading module hook 'hook-pandas.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
24325 INFO: Loading module hook 'hook-PyQt5.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
24542 WARNING: Hidden import "sip" not found!
24542 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
24543 INFO: Loading module hook 'hook-pytz.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
24660 INFO: Loading module hook 'hook-lib2to3.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
24687 INFO: Loading module hook 'hook-encodings.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
24767 INFO: Loading module hook 'hook-PIL.ImageFilter.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
24776 INFO: Excluding import of numpy from module PIL.ImageFilter
24776 INFO: Loading module hook 'hook-distutils.util.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
24780 INFO: Excluding import of lib2to3.refactor from module distutils.util
24780 INFO: Loading module hook 'hook-PIL.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
24782 INFO: Import to be excluded not found: 'FixTk'
24783 INFO: Import to be excluded not found: 'tkinter'
24785 INFO: Excluding import of PyQt5.QtGui from module PIL.ImageQt
24785 INFO: Excluding import of PyQt5.QtCore from module PIL.ImageQt
24785 INFO: Loading module hook 'hook-setuptools.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
25671 INFO: Import to be excluded not found: 'setuptools.py33compat'
25672 INFO: Import to be excluded not found: 'setuptools.py27compat'
25672 INFO: Loading module hook 'hook-PyQt5.QtGui.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
25710 INFO: Loading module hook 'hook-PIL.Image.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26303 INFO: Loading module hook 'hook-packaging.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26304 INFO: Loading module hook 'hook-pickle.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26309 INFO: Excluding import of argparse from module pickle
26309 INFO: Loading module hook 'hook-heapq.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26312 INFO: Excluding import of doctest from module heapq
26312 INFO: Loading module hook 'hook-difflib.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26316 INFO: Excluding import of doctest from module difflib
26316 INFO: Loading module hook 'hook-PySide2.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26377 WARNING: Cannot read QLibraryInfo output: raised Expecting value: line 1 column 1 (char 0) when decoding:
False
26378 INFO: Loading module hook 'hook-PyQt5.QtWidgets.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26437 INFO: Loading module hook 'hook-multiprocessing.util.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26444 INFO: Excluding import of test from module multiprocessing.util
26444 INFO: Loading module hook 'hook-sysconfig.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26456 INFO: Loading module hook 'hook-numpy.core.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26458 INFO: Loading module hook 'hook-xml.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26564 INFO: Loading module hook 'hook-numpy.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26565 INFO: Loading module hook 'hook-distutils.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26567 INFO: Loading module hook 'hook-numpy._pytesttester.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26570 INFO: Excluding import of pytest from module numpy._pytesttester
26571 INFO: Loading module hook 'hook-PyQt5.QtCore.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26581 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26584 INFO: Import to be excluded not found: 'FixTk'
26586 INFO: Loading module hook 'hook-setuptools.msvc.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26590 INFO: Excluding import of numpy from module setuptools.msvc
26591 INFO: Loading module hook 'hook-_tkinter.py' from '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks'...
26807 INFO: checking Tree
26807 INFO: Building Tree because Tree-00.toc is non existent
26807 INFO: Building Tree Tree-00.toc
26854 INFO: checking Tree
26854 INFO: Building Tree because Tree-01.toc is non existent
26854 INFO: Building Tree Tree-01.toc
26964 INFO: checking Tree
26965 INFO: Building Tree because Tree-02.toc is non existent
26965 INFO: Building Tree Tree-02.toc
27030 INFO: Looking for ctypes DLLs
27083 WARNING: library user32 required via ctypes not found
27090 WARNING: library msvcrt required via ctypes not found
27131 INFO: Analyzing run-time hooks ...
27141 INFO: Including run-time hook '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks/rthooks/pyi_rth_multiprocessing.py'
27146 INFO: Including run-time hook '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks/rthooks/pyi_rth_pkgres.py'
27149 INFO: Including run-time hook '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks/rthooks/pyi_rth_pyqt5.py'
27151 INFO: Including run-time hook '/usr/local/lib/python3.9/site-packages/PyInstaller/hooks/rthooks/pyi_rth__tkinter.py'
27176 INFO: Looking for dynamic libraries
27951 INFO: Looking for eggs
27951 INFO: Using Python library /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/Python
27964 INFO: Warnings written to /Users/alisa/Dropbox/cff/Python/MyScriptFolder/build/test/warn-test.txt
28106 INFO: Graph cross-reference written to /Users/alisa/Dropbox/cff/Python/MyScriptFolder/build/test/xref-test.html
28191 INFO: checking PYZ
28191 INFO: Building PYZ because PYZ-00.toc is non existent
28192 INFO: Building PYZ (ZlibArchive) /Users/alisa/Dropbox/cff/Python/MyScriptFolder/build/test/PYZ-00.pyz
29650 INFO: Building PYZ (ZlibArchive) /Users/alisa/Dropbox/cff/Python/MyScriptFolder/build/test/PYZ-00.pyz completed successfully.
29673 INFO: checking PKG
29673 INFO: Building PKG because PKG-00.toc is non existent
29673 INFO: Building PKG (CArchive) PKG-00.pkg
29711 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
29713 INFO: Bootloader /usr/local/lib/python3.9/site-packages/PyInstaller/bootloader/Darwin-64bit/runw
29713 INFO: checking EXE
29713 INFO: Building EXE because EXE-00.toc is non existent
29713 INFO: Building EXE from EXE-00.toc
29713 INFO: Appending archive to EXE /Users/alisa/Dropbox/cff/Python/MyScriptFolder/build/test/test
29725 INFO: Fixing EXE for code signing /Users/alisa/Dropbox/cff/Python/MyScriptFolder/build/test/test
29734 INFO: Building EXE from EXE-00.toc completed successfully.
29738 INFO: checking COLLECT
29738 INFO: Building COLLECT because COLLECT-00.toc is non existent
29739 INFO: Building COLLECT COLLECT-00.toc
37925 INFO: Building COLLECT COLLECT-00.toc completed successfully.
37987 INFO: checking BUNDLE
37987 INFO: Building BUNDLE because BUNDLE-00.toc is non existent
37987 INFO: Building BUNDLE BUNDLE-00.toc
43659 INFO: moving BUNDLE data files to Resource directory
@rokm
Copy link
Member

rokm commented Mar 16, 2021

The error is actually coming from pandas, which is imported by pytesseract:

  File "pandas/_libs/testing.pyx", line 1, in init pandas._libs.testing
ModuleNotFoundError: No module named 'cmath'

This was fixed in #5630, which was merged to develop.

But you can also easily fix it by adding --hiddenimport cmath to your pyinstaller command.

@gauthierbuttez
Copy link
Author

Thank you so much @rokm

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants