ModuleNotFoundError:运行由 PyInstaller 编译的 Mac OS 应用程序时没有名为“cmath”的模块:PyTesseract 的问题

时间:2021-03-16 17:38:42

标签: python-3.x pyinstaller

我正在尝试在 MAC OS Catalina 上使用 PyInstaller 编译我的 Python 3.9 脚本: MAC OS CATALINA 10.15.6 蟒蛇 3.9 pyinstaller 4.2

当我从 Mac 上的终端运行我的 python 脚本时,它运行良好,没有任何问题。

我用这个命令编译:

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

这里是 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)

当我双击应用程序时,它不会启动该应用程序。所以我通过命令行打开它:

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

显示终端窗口,几秒钟后出现此错误消息:

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

所以我搜索安装 cmath,但我不能。 所以我将它添加为规范文件中的隐藏导入,但它不起作用。

mymodules.py 中的这一行 46 是 Tesseract Python 模块的导入:

import pytesseract

所以我试图用这个最少的代码重现这个问题:

import pytesseract

print("Hello")

我遇到了完全相同的问题!!!所以PyInstaller编译pytesseract有问题?

1 个答案:

答案 0 :(得分:0)

如 GitHub 问题中的 here 所示(看起来是您的帖子)。我也遇到了同样的问题并为我解决了只需将 --hiddenimport cmath 添加到您的 pyinstaller 命令