# Trouble exporting figures from plotly using orca

• Python

## Summary:

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.

## Main Question or Discussion Point

Python:
from plotly import graph_objects as go
import plotly.io as pio

arabella=go.Figure()

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:
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

Related Programming and Computer Science News on Phys.org
jedishrfu
Mentor
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

jedishrfu
Mentor
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:
from plotly import graph_objects as go
import plotly.io as pio

arabella=go.Figure()

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")
It still returns the same error message. I do not know why that is.

jedishrfu
Mentor
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"

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.

Python:
from plotly import graph_objects as go
import plotly.io as pio

arabella=go.Figure()

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")
It exports a plain file, and not a png file, as intended.

jedishrfu
Mentor
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?

jedishrfu
Mentor
so it didn't return the file arrabella.png like you specified?

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.

pbuk
Gold Member
Python:
direc="C:/Users/Eclair/Documents/2 LaTeX/active/arabella"
...
arabella.write_image(direc,".png")
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:
Python:
file_path="C:/Users/Eclair/Documents/2 LaTeX/active/arabella/my-file-name.png"
...
arabella.write_image(file_path)

Last edited:
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.