We're currently unable to use plotly write_image. A stacktrace is thrown and the terminal completely hangs (it doesn't even respond to control + C). This is related to kaleido and I've seen a number of other posts recommending to downgrade to kaleido 0.1.0, however this version is now almost 5 years old and it feels like there must be a more current solution.
Our installation is python 3.11.13, kaleido 1.1.0, plotly 6.3.0. We're running a very simple test with the following code:
import plotly.express as px
import pandas as pd
out_dir = "C:/Temp"
xs = pd.date_range('01-01-2025', '02-01-2025')
ys = range(len(xs))
fig = px.line(x=xs,y=ys)
fig.write_html( f'{out_dir}/test1.html')
fig.write_image(f'{out_dir}/test1.png', width=fig.layout.width, height=fig.layout.height)
The write_html works fine, however the write_image produces a large stacktrace, the last bit being:
File "C:\Apps\Miniconda3\envs\risk311\Lib\site-packages\choreographer\browser_async.py", line 131, in run
return subprocess.Popen( # noqa: S603
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Apps\Miniconda3\envs\risk311\Lib\subprocess.py", line 1026, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Apps\Miniconda3\envs\risk311\Lib\subprocess.py", line 1538, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [WinError 5] Access is denied
At this point the process hangs, and the terminal is frozen. The question is - access is denied to what exactly? I'm running as an administrator, and the write_html works so its not the destination folder ...
Two additional notes - we do NOT have Chrome installed, which (sadly) is needed by kaleido. However, we do have Edge, and from following the documentation, we have properly set the following env variable: BROWSER_PATH="C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
Second, this only happens when running a cmd wrapper script to activate the conda environment and run the above python code. If I open a console interactively and manually enter every line of the wrapper and the script above, it runs without problems. We use this wrapper for all of our scheduled jobs without issue, and it is the following:
set BROWSER_PATH="C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
set env_name="risk311"
set conda_path="C:\ProgramData\miniconda3"
set env_path="C:\Apps\Miniconda3\envs\risk311"
:: activate env
call %conda_path%\condabin\conda.bat activate %env_name%
%env_path%\python.exe <path to python script>
In both cases I'm running as a local administrator on the server.
I can downgrade kaleido if needed, but was hoping a more current solution might be available - thanks!