I’m building an exe using pyinstaller. A line of code involves writing a static image in the usual way like this:
fig.write_image(file=thumb_file, format='jpeg', scale=0.4)
I’ve installed conda install -c conda-forge python-kaleido=0.1.0
as per plotly write_image() runs forever and doesn’t produce any static image
However when building the exe I get the error :
The kaleido executable is required by the kaleido Python library, but it was not included in the Python package and it could not be found on the system PATH.
Searched for included kaleido executable at: etc
ChatGPT was its usual unhelpful self and suggested the spec file as below:
# -*- mode: python ; coding: utf-8 -*-
import os
from PyInstaller.utils.hooks import collect_submodules, collect_data_files, copy_metadata
block_cipher = None
# Path to python-kaleido directory within your environment
kaleido_dir = r"C:Users....anaconda3envs***Libsite-packageskaleido"
# Include all files from kaleido_dir and its subdirectories
kaleido_files = [(kaleido_dir, 'kaleido')]
a = Analysis(['***.py'],
pathex=[],
binaries=[],
datas=kaleido_files + [some stuff here]
+ collect_data_files('scipy', include_py_files=True),
hiddenimports=['pkg_resources.py2_warn', 'openpyxl.cell._writer']
+ collect_submodules('scipy'),
hookspath=[],
runtime_hooks=[],
excludes=['scipy._lib.array_api_compat.torch'],
debug=True,
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,
a.binaries,
a.zipfiles,
a.datas,
name='***',
debug=True,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=['*kaleido*'],
runtime_tmpdir=None,
onefile=True,
console=True)
I also included the following before importing plotly
if getattr(sys, 'frozen', False):
# the application is bundled
kaleido_bundled_dir = os.path.join(sys._MEIPASS, 'kaleido')
sys.path.append(kaleido_bundled_dir)
How can I get this to run correctly?