Trouble exporting figures from plotly using orca

  • Context: Python 
  • Thread starter Thread starter Eclair_de_XII
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around issues related to exporting figures from Plotly using the Orca tool. Participants explore problems encountered during the export process, including error messages and file output formats. The conversation includes technical troubleshooting and configuration settings.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • The original poster (OP) encounters an error when trying to export a figure, indicating that the Orca executable may not be correctly configured.
  • Some participants suggest that the executable path provided by the OP does not point to a valid Windows executable, recommending the use of the full path to the Orca executable.
  • One participant mentions that the executable line should typically be just "orca" if it is in the system path.
  • The OP later finds the Orca executable but continues to experience the same error after updating the path in the code.
  • Another participant advises adding the Orca directory to the Windows command environment path to facilitate locating the executable.
  • There is confusion about whether the exported file should have an extension, as the OP reports receiving a plain file without an extension.
  • One participant clarifies that the argument to the `write_image` function should include the full file path with a filename and extension to ensure proper export.

Areas of Agreement / Disagreement

Participants express various views on the configuration of the Orca executable and the expected behavior of the export function. While some suggestions lead to successful outcomes, there is no consensus on the initial cause of the error or the best configuration method.

Contextual Notes

Participants mention potential dependencies and configuration issues that could affect the functionality of the Orca tool. There are also discussions about the correct usage of file paths and extensions when exporting images.

Who May Find This Useful

This discussion may be useful for users of Plotly who are experiencing similar issues with exporting figures using Orca, particularly those working in a Windows environment and dealing with file path configurations.

Eclair_de_XII
Messages
1,082
Reaction score
91
TL;DR
I have a bunch of figures created, and I wish to save them all into one folder in order to save myself the trouble of showing the figures on my browser, and then downloading each and every one of them.

To this end, I am following the instructions described here on how to do so:

https://plotly.com/python/static-image-export/

I am not skilled in programming, so I do not know why my command lines do not perform the intended function and return, instead, the error messages to be found below.
Python:
from plotly import graph_objects as go
import plotly.io as pio

arabella=go.Figure()

arabella.add_trace(go.Scatter(
    x=[0,0,1,1,0],
    y=[0,1,1,0,0],
    text=["Origin","$e_2$","","$e_1$"],
    textposition=["bottom left","top left","top center","bottom right"],
    mode='text+lines+markers'
))

orca="C:/Users/Eclair/.plotly/.orca"
direc="C:/Users/Eclair/Documents/2 LaTeX/active/"

pio.orca.config.executable=orca
pio.orca.config.save()

arabella.write_image(direc,"arabella.png")

I executed this code, and the following error message was returned to me:

Code:
C:\Users\Eclair\AppData\Local\Programs\Python\Python38-32\python.exe C:/Users/Eclair/.PyCharmCE2019.3/config/scratches/scratch_1.py
Traceback (most recent call last):
  File "C:/Users/Eclair/.PyCharmCE2019.3/config/scratches/scratch_1.py", line 20, in <module>
    arabella.write_image(direc,"arabella.png")
  File "C:\Users\Eclair\AppData\Roaming\Python\Python38\site-packages\plotly\basedatatypes.py", line 2824, in write_image
    return pio.write_image(self, *args, **kwargs)
  File "C:\Users\Eclair\AppData\Roaming\Python\Python38\site-packages\plotly\io\_orca.py", line 1766, in write_image
    img_data = to_image(
  File "C:\Users\Eclair\AppData\Roaming\Python\Python38\site-packages\plotly\io\_orca.py", line 1532, in to_image
    ensure_server()
  File "C:\Users\Eclair\AppData\Roaming\Python\Python38\site-packages\plotly\io\_orca.py", line 1390, in ensure_server
    validate_executable()
  File "C:\Users\Eclair\AppData\Roaming\Python\Python38\site-packages\plotly\io\_orca.py", line 1144, in validate_executable
    p = subprocess.Popen(
  File "C:\Users\Eclair\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Eclair\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application

Process finished with exit code 1

If it matters, I am using the PyCharm interpreter. I did a bunch of searches on this issue, using the words on the last line as my search criteria. The answers ranged from what I presume to be bad directories, the interpreter's inability to find the executable orca file, and some other stuff that I am too code-illiterate to understand. I tried doing the thing requested by the error message and using the plotly.io.config.executable attribute in order to set the directory for the orca executable, which I assumed was the file referred to in this code:

Python:
import plotly.io as pio

print(pio.orca.config)

[CODE highlight="20"]C:\Users\Eclair\AppData\Local\Programs\Python\Python38-32\python.exe C:/Users/Eclair/.PyCharmCE2019.3/config/scratches/scratch_1.py
orca configuration
------------------
server_url: None
executable: C:/Users/Eclair/.plotly/.orca
port: None
timeout: None
default_width: None
default_height: None
default_scale: 1
default_format: png
mathjax: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js
topojson: None
mapbox_access_token: None
use_xvfb: auto

constants
---------
plotlyjs: C:\Users\Eclair\AppData\Roaming\Python\Python38\site-packages\plotly\package_data\plotly.min.js
config_file: C:\Users\Eclair\.plotly\.orca[/CODE]
 
Technology news on Phys.org
You are likely missing some dependency like a window executable program that Is called by orca to do some work.

in your configuration the executable attribute doesn’t look like a valid windows executable name usually it would be something like C:\xxx\xxx.exe

so I would search around for that too as it may be the source of the error.

also maybe instead of the directory of the executable you provide the full path to the orca executable
 
In this example, the executable line is simply orca

https://plotly.com/python/orca-management/

anyway you might find more stuff there as well

the article also mentions that plotless will search for the orca executable along the path so the path must have directory that contains the orca executable.
 
I finally managed to find the orca.exe file; it turns out I had had it installed for almost two weeks, but did not know where it was. In any case, though, I've tried to link to the executable directly by making the correction to the code I posted in the opening post.

[CODE highlight="14"]from plotly import graph_objects as go
import plotly.io as pio

arabella=go.Figure()

arabella.add_trace(go.Scatter(
x=[0,0,1,1,0],
y=[0,1,1,0,0],
text=["Origin","$e_2$","","$e_1$"],
textposition=["bottom left","top left","top center","bottom right"],
mode='text+lines+markers'
))

orca="C:/Users/Eclair/AppData/Local/Programs/orca/orca"
direc="C:/Users/Eclair/Documents/2 LaTeX/active/"

pio.orca.config.executable=orca
pio.orca.config.save()

print(pio.orca.config)

arabella.write_image(direc,"arabella.png")[/CODE]

It still returns the same error message. I do not know why that is.
error.png
 
try placing "C:/Users/Eclair/AppData/Local/Programs/orca" in your windows command environment path parameter

and change the line:

Python:
pio.orca.config.executable="orca"

or

Python:
pio.orca.config.executable="orca.exe"
 
jedishrfu said:
try placing "C:/Users/Eclair/AppData/Local/Programs/orca" in your windows command environment path parameter

I do not understand. Are you referring to the parameter named in line 14? I did try to fix the problem by appending ".exe" to the end of the string in this parameter, but I am not sure if I did it correctly.

[CODE lang="python" highlight="14"]from plotly import graph_objects as go
import plotly.io as pio

arabella=go.Figure()

arabella.add_trace(go.Scatter(
x=[0,0,1,1,0],
y=[0,1,1,0,0],
text=["Origin","$e_2$","","$e_1$"],
textposition=["bottom left","top left","top center","bottom right"],
mode='text+lines+markers'
))

orca="C:/Users/Eclair/AppData/Local/Programs/orca/orca.exe"
direc="C:/Users/Eclair/Documents/2 LaTeX/active/arabella"

pio.orca.config.executable=orca
pio.orca.config.save()

arabella.write_image(direc,".png")[/CODE]

It exports a plain file, and not a png file, as intended.

error.png
 
Windows has a path parameter.

When you're in a command session and type path you get to see what its value is. Windows uses it to search for commands that you might type in.

The website I sent earlier mentions the same thing. It says python will use the path to locate the orca command so you need to add the orca command directory to the path.

To set it on Windows:

https://www.computerhope.com/issues/ch000549.htm
 
I am not sure if I have done this correctly. Is it normal for plotly to export images as plain files with no extensions?
error.png
 
so it didn't return the file arrabella.png like you specified?
 
  • #10
It returns a plain file with no extension. I am not sure if this is intended or not. I can still open it using Paint and it will appear as if it were an image file, though. I was hoping to use the exported images in a LaTeX document, but I can likely find a way to use it as is.
 
  • #11
Eclair_de_XII said:
[CODE lang="python"]
direc="C:/Users/Eclair/Documents/2 LaTeX/active/arabella"
...
arabella.write_image(direc,".png")[/CODE]

It exports a plain file, and not a png file, as intended.
It exports a file named C:/Users/Eclair/Documents/2 LaTeX/active/arabella because the argument to write_image is the filename to write, not a directory. So try:
[CODE lang="python"]
file_path="C:/Users/Eclair/Documents/2 LaTeX/active/arabella/my-file-name.png"
...
arabella.write_image(file_path)[/CODE]
 
Last edited:
  • Like
Likes   Reactions: Eclair_de_XII
  • #12
That works. Thank you for all your help. I apologize; I probably should have asked this question at a proper technical support forum instead of at this one.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 9 ·
Replies
9
Views
10K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
3
Views
2K
Replies
5
Views
16K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 17 ·
Replies
17
Views
3K