简体   繁体   中英

Plotly write.image() freezes with kaleido 0.2.1

I read tens of related questions but none of them solved my issue.

Setup

Currently I'm using Python 3.9.12 in a conda environment (named 'plot_env', conda version = 4.13.0). For completeness here I show conda info and conda list output.

(plot_env) PS C:\windows\System32> conda info
active environment : plot_env
active env location : C:\Users\mirko\anaconda3\envs\plot_env
shell level : 2
user config file : C:\Users\mirko\.condarc
populated config files : C:\Users\mirko\.condarc
conda version : 4.13.0
conda-build version : 3.21.8
python version : 3.9.12.final.0
virtual packages : __win=0=0=1=x86_64
base environment : C:\Users\mirko\anaconda3  (writable)
conda av data dir : C:\Users\mirko\anaconda3\etc\conda
conda av metadata url : None
channel URLs : https://repo.anaconda.com/pkgs/main/win-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/win-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/msys2/win-64
https://repo.anaconda.com/pkgs/msys2/noarch
package cache : C:\Users\mirko\anaconda3\pkgs
C:\Users\mirko\.conda\pkgs
C:\Users\mirko\AppData\Local\conda\conda\pkgs
envs directories : C:\Users\mirko\anaconda3\envs
C:\Users\mirko\.conda\envs
C:\Users\mirko\AppData\Local\conda\conda\envs
platform : win-64
user-agent : conda/4.13.0 requests/2.27.1 CPython/3.9.12 Windows/10 Windows/10.0.22000
administrator : False
netrc file : None
offline mode : False

(plot_env) PS C:\windows\System32> conda list
# packages in environment at 
C:\Users\mirko\anaconda3\envs\plot_env:
#
# Name                    Version                   Build  
Channel
asttokens                 2.0.8                    pypi_0    pypi
attrs                     22.1.0                   pypi_0    pypi
backcall                  0.2.0                    pypi_0    pypi
ca-certificates           2022.07.19           haa95532_0
certifi                   2022.6.15        py39haa95532_0
colorama                  0.4.5                    pypi_0    pypi
debugpy                   1.6.3                    pypi_0    pypi
decorator                 5.1.1                    pypi_0    pypi
entrypoints               0.4                      pypi_0    pypi
et-xmlfile                1.1.0                    pypi_0    pypi
executing                 0.10.0                   pypi_0    pypi
fastjsonschema            2.16.1                   pypi_0    pypi
ipykernel                 6.15.1                   pypi_0    pypi
ipython                   8.4.0                    pypi_0    pypi
jedi                      0.18.1                   pypi_0    pypi
jsonschema                4.10.3                   pypi_0    pypi
jupyter-client            7.3.4                    pypi_0    pypi
jupyter-core              4.11.1                   pypi_0    pypi
kaleido                   0.2.1                    pypi_0    pypi
matplotlib-inline         0.1.6                    pypi_0    pypi
nbformat                  5.4.0                    pypi_0    pypi
nest-asyncio              1.5.5                    pypi_0    pypi
numpy                     1.23.2                   pypi_0    pypi
openpyxl                  3.0.10                   pypi_0    pypi
openssl                   1.1.1q               h2bbff1b_0
packaging                 21.3                     pypi_0    pypi
pandas                    1.4.3                    pypi_0    pypi
parso                     0.8.3                    pypi_0    pypi
pickleshare               0.7.5                    pypi_0    pypi
pip                       22.1.2           py39haa95532_0
plotly                    5.10.0                   pypi_0    pypi
prompt-toolkit            3.0.30                   pypi_0    pypi
psutil                    5.9.1                    pypi_0    pypi
pure-eval                 0.2.2                    pypi_0    pypi
pygments                  2.13.0                   pypi_0    pypi
pyparsing                 3.0.9                    pypi_0    pypi
pyrsistent                0.18.1                   pypi_0    pypi
python                    3.9.12               h6244533_0
python-dateutil           2.8.2                    pypi_0    pypi
pytz                      2022.2.1                 pypi_0    pypi
pywin32                   304                      pypi_0    pypi
pyzmq                     23.2.1                   pypi_0    pypi
setuptools                61.2.0           py39haa95532_0
six                       1.16.0                   pypi_0    pypi
sqlite                    3.39.2               h2bbff1b_0
stack-data                0.4.0                    pypi_0    pypi
tenacity                  8.0.1                    pypi_0    pypi
tornado                   6.2                      pypi_0    pypi
traitlets                 5.3.0                    pypi_0    pypi
tzdata                    2022a                hda174b7_0
vc                        14.2                 h21ff451_1
vs2015_runtime            14.27.29016          h5e58377_2
wcwidth                   0.2.5                    pypi_0    pypi
wheel                     0.37.1             pyhd3eb1b0_0
wincertstore              0.2              py39haa95532_2

Minimal working example

import plotly.express as px
import plotly.io as pio
x = [1,2,3]
y = [2,3,4]
fig=px.scatter(x, y)
pio.write_image(fig, './figure', format='png')

After running this script the write.image() command freeze and the output in the terminal doen't show anything.

What I already Tried

Following some tips i found on the internet I tried:

Installing kaleido 0.1.0: this just turned the problem to something else. When i try to run the script with kaleido 0.1.0 the output is the following

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:
C:\Program Files\GitHub CLI
C:\Users\mirko\AppData\Local\Microsoft\WindowsApps
C:\Users\mirko\AppData\Local\Programs\Microsoft VS Code\bin
C:\Users\mirko\anaconda3\Library\bin
C:\Users\mirko\anaconda3\Scripts
C:\Users\mirko\anaconda3\condabin
C:\Users\mirko\AppData\Local\GitHubDesktop\bin
C:\Program Files\heroku\bin

So I added the specific path to my kaleido.cmd to Path, but this passage looks pretty sketchy to me because it means I will need to repeat it every time i create a new environment with kaleido installed.
This solved the issue: I exported the correct png image. So my main question is: How do I solve this problem once and for all?

Using kaleido 0.2.1: nothing seems to solve the issue. The terminal just freezes and i can't use ctrl+C to print a log of the errors. I tried setting pio.kaleido.scope.mathjax = None but it did nothing.

You can probably get away with:

conda install -c conda-forge kaleido-core=0.2.1

However, I'd lean toward recreating the environment with Conda packages prioritized (at least for stuff that needs non-Python components):

conda create -n plot_env2 -c conda-forge python=3.9 python-kaleido

so that Conda can properly handle all the non-Python dependencies, which is its specialty.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM