Open adamcperez opened 2 years ago
Are you in a virtual environment and/or Python 3.9.12? And are you able to provide more steps to reproduce the error?
I am getting something similar when I try to use fig.write_image() in a pipenv virtual environment. It only seems to have started up after making the update from 3.9.10 -> 3.9.12.
fig.write_image(plot_outfile + '.png')
Produces this error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
File <path to .venv>/lib/python3.9/site-packages/plotly/basedatatypes.py:3829, in BaseFigure.write_image(self, *args, **kwargs)
]()[3769]()[ """
]()[3770]()[ Convert a figure to a static image and write it to a file or writeable
]()[3771]()[ object
(...)
]()[3825]()[ None
]()[3826]()[ """
]()[3827]()[ import plotly.io as pio
-> ]()[3829]()[ return pio.write_image(self, *args, **kwargs)
File <path to .venv>/lib/python3.9/site-packages/plotly/io/_kaleido.py:268, in write_image(fig, file, format, scale, width, height, validate, engine)
]()[252]()[ raise ValueError(
]()[253]()[ """
]()[254]()[ Cannot infer image type from output path '{file}'.
(...)
]()[262]()[ )
]()[263]()[ )
]()[265]()[ # Request image
]()[266]()[ # -------------
]()[267]()[ # Do this first so we don't create a file if image conversion fails
--> ]()[268]()[ img_data = to_image(
]()[269]()[ fig,
]()[270]()[ format=format,
]()[271]()[ scale=scale,
]()[272]()[ width=width,
]()[273]()[ height=height,
]()[274]()[ validate=validate,
]()[275]()[ engine=engine,
]()[276]()[ )
]()[278]()[ # Open file
]()[279]()[ # ---------
]()[280]()[ if path is None:
]()[281]()[ # We previously failed to make sense of `file` as a pathlib object.
]()[282]()[ # Attempt to write to `file` as an open file descriptor.
File <path to .venv>/lib/python3.9/site-packages/plotly/io/_kaleido.py:145, in to_image(fig, format, width, height, scale, validate, engine)
]()[142]()[ # Validate figure
]()[143]()[ # ---------------
]()[144]()[ fig_dict = validate_coerce_fig_to_dict(fig, validate)
--> ]()[145]()[ img_bytes = scope.transform(
]()[146]()[ fig_dict, format=format, width=width, height=height, scale=scale
]()[147]()[ )
]()[149]()[ return img_bytes
File <path to .venv>/lib/python3.9/site-packages/kaleido/scopes/plotly.py:153, in PlotlyScope.transform(self, figure, format, width, height, scale)
]()[142]()[ raise ValueError(
]()[143]()[ "Invalid format '{original_format}'.\n"
]()[144]()[ " Supported formats: {supported_formats_str}"
(...)
]()[148]()[ )
]()[149]()[ )
]()[151]()[ # Transform in using _perform_transform rather than superclass so we can access the full
]()[152]()[ # response dict, including error codes.
--> ]()[153]()[ response = self._perform_transform(
]()[154]()[ figure, format=format, width=width, height=height, scale=scale
]()[155]()[ )
]()[157]()[ # Check for export error, later can customize error messages for plotly Python users
]()[158]()[ code = response.get("code", 0)
File <path to .venv>/lib/python3.9/site-packages/kaleido/scopes/base.py:293, in BaseScope._perform_transform(self, data, **kwargs)
]()[284]()[ """
]()[285]()[ Transform input data using the current scope, returning dict response with error code
]()[286]()[ whether successful or not.
(...)
]()[290]()[ :return: Dict of response from Kaleido executable, whether successful or not
]()[291]()[ """
]()[292]()[ # Ensure that kaleido subprocess is running
--> ]()[293]()[ self._ensure_kaleido()
]()[295]()[ # Perform export
]()[296]()[ export_spec = self._json_dumps(dict(kwargs, data=data)).encode('utf-8')
File <path to .venv>/lib/python3.9/site-packages/kaleido/scopes/base.py:198, in BaseScope._ensure_kaleido(self)
]()[193]()[ if not startup_response_string:
]()[194]()[ message = (
]()[195]()[ "Failed to start Kaleido subprocess. Error stream:\n\n" +
]()[196]()[ self._get_decoded_std_error()
]()[197]()[ )
--> ]()[198]()[ raise ValueError(message)
]()[199]()[ else:
]()[200]() startup_response = json.loads(startup_response_string)
ValueError: Failed to start Kaleido subprocess. Error stream:
<path to .venv>/lib/python3.9/site-packages/kaleido/executable/kaleido: line 4: cd: <path to something>: No such file or directory
<path to .venv>/lib/python3.9/site-packages/kaleido/executable/kaleido: line 5: ./bin/kaleido: No such file or directory
kaleido==0.2.1 pipenv==2022.3.28 plotly==5.6.0 python==3.9.12 Mac OS Monterey (12.3), Intel chip
Output of "python3 -m pip show kaleido": Name: kaleido Version: 0.2.1 Summary: Static image export for web-based visualization libraries with zero dependencies Home-page: UNKNOWN Author: Jon Mease Author-email: jon@plotly.com License: MIT Location: <path to .venv>/lib/python3.9/site-packages Requires: Required-by:
I am sorry that I am currently unable to create an example at the moment, but will try to check in later.
Maybe a clue, this error seems to be thrown by a space in the path of the target output file:
<path to .venv>/lib/python3.9/site-packages/kaleido/executable/kaleido: line 4: cd: <path to something>: No such file or directory
As it's basically
line 4: cd: /Users/username/Dropbox: No such file or directory
where the target should be '/Users/username/Dropbox (some words)/morepath/morepath/something'
This may be related to Issue https://github.com/plotly/Kaleido/issues/78
Hi, i had same error. My file name is maked about a column. This name file had blank spaces. i deleted these spaces with strip method. So , the error was never more.
df['Name'] = df['Name'].str.strip()
fig.write_image(f"{name}-count_emoji.jpg",format="jpg")
Thanks for your interest in Kaleido. We are currently working on an overhaul that might address your issue - we hope to have news in a few weeks and will post an update then. Thanks - @gvwilson
Receiving the following error when trying to write a plotly graph object/px using the kaleido engine.
I have uninstalled and re installed kaleido using both installation methods. Checked packages within the anaconda environment and is not showing under installed.
ValueError: Image export using the "kaleido" engine requires the kaleido package, which can be installed using pip: $ pip install -U kaleido