4

I´m trying to export the plot into a jpg file. For that, I´m using this code:

from plotly.offline import iplot, init_notebook_mode
import plotly.graph_objs as go
import plotly.io as pio
import plotly

import os
import numpy as np

init_notebook_mode(connected=True)

N = 100
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
sz = np.random.rand(N)*30

fig = go.Figure()
fig.add_scatter(x=x,
                y=y,
                mode='markers',
                marker={'size': sz,
                        'color': colors,
                        'opacity': 0.6,
                        'colorscale': 'Viridis'
                       });
iplot(fig)

pio.write_image(fig, 'fig1.png')

The problem that I have is with ORCA. This lib can be locate but it’s installed. This is the error that I got:

ValueError: The orca executable is required in order to export figures as static images, but the executable that was found at '/opt/conda/bin/orca' does not seem to be a valid plotly orca executable. Please refer to the end of this message for details on what went wrong.

If you haven't installed orca yet, you can do so using conda as follows:

$ conda install -c plotly plotly-orca

Alternatively, see other installation methods in the orca project README at https://github.com/plotly/orca.

After installation is complete, no further configuration should be needed.

If you have installed orca, then for some reason plotly.py was unable to locate it. In this case, set the plotly.io.orca.config.executable property to the full path of your orca executable. For example:

>>> plotly.io.orca.config.executable = '/path/to/orca'

After updating this executable property, try the export operation again. If it is successful then you may want to save this configuration so that it will be applied automatically in future sessions. You can do this as follows:

>>> plotly.io.orca.config.save() 

If you're still having trouble, feel free to ask for help on the forums at https://community.plot.ly/c/api/python

Here is the error that was returned by the command $ /opt/conda/bin/orca --help

[Return code: 127] /opt/conda/lib/orca_app/orca: error while loading shared libraries: libXtst.so.6: cannot open shared object file: No such file or directory

Note: When used on Linux, orca requires an X11 display server, but none was detected. Please install X11, or configure your system with Xvfb. See the orca README (https://github.com/plotly/orca) for instructions on using orca with Xvfb.

Anyone know how to fix this error?

Alberto Aguilera
  • 311
  • 1
  • 5
  • 13

6 Answers6

4

I had to invest significant effort in order to get Orca to work on Ubuntu 18 in my Django 2 project. Here is what I did that finally worked:

I did this on Ubuntu 18.04.3 LTS

In the below it is assumed that your user name is USERNAME and your virtual environment directory is named "myvenv"

  1. Get the Orca AppImage file to /home/USERNAME/myvenv/bin and change the rights on the file

wget https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage chmod +x orca-1.2.1-x86_64.AppImage

  1. Install the following packages

sudo apt-get install desktop-file-utils
sudo apt-get install libgtk2.0-0 sudo apt-get install libgconf-2-4 sudo apt-get install xvfb sudo apt-get install chromium-browser

  1. Create a file named orca in /home/USERNAME/myvenv/bin/ with the following content:

#!/bin/bash

xvfb-run -a orca-1.2.1-x86_64.AppImage "$@"

KittenCrypto
  • 121
  • 1
  • 5
1

The solution is on plotly/orca

This i what I have done and it solved my issue:

  1. Download orca-1.2.1-x86_64.AppImage

  2. Make a softlink by ln -s orca-1.2.1-x86_64.AppImage orca, then you see orca -> orca-1.2.1-x86_64.AppImage*

  3. create a file and name it orca-executable.sh and its content is

    #!/bin/bash

    xvfb-run -a orca "$@"

Then add below line into your script

plotly.io.orca.config.executable = '/path/to/orca/orca-executable.sh'

Files under path /path/to/orca:

rwxrwxrwx 1 root root       26 Feb 14 03:09 orca -> orca-1.2.1-x86_64.AppImage*
-rwxr-xr-x 1 root root 51607939 Feb 14 03:08 orca-1.2.1-x86_64.AppImage*
-rwxr-xr-x 1 root root       34 Feb 14 03:33 orca-executable.sh*
Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125
  • A similar approach even allows orca to be used inside a Docker container on a headless system as discussed [here](https://github.com/plotly/orca/issues/150), which enables accessing machines with orca already installed simply using a browser and the MyBinder system. Links are on that page if you want to spin up such a machine or see [here](https://github.com/fomightez/orca-plotly-binderized) to launch one. – Wayne Jun 04 '19 at 20:45
  • hi @Haifeng Zhang, is your os ubuntu? I see you have Xvfb installed, but did you install libgtk2.0-0, libgconf-2-4 and chromium-browser too? Mine is AWS Linux, which does not have libgtk2.0-0, libgconf-2-4 . I downloaded orca-1.2.1-x86_64.AppImage (use --appimage-extract to unpack it) and follow your approach but orca.sh is giving "/usr/bin/xvfb-run: line 166: 0: command not found" error. See my post https://stackoverflow.com/questions/62639101/plotly-orca-not-working-on-aws-ec2-instance – ngBeginner Jul 03 '20 at 09:40
1

What worked for me on Windows is:

  • Following https://github.com/plotly/orca#installation - Method 4: Standalone binaries:

    • Download windows-release.zip from https://github.com/plotly/orca/releases
    • Install the executable
    • Right click on the desktop newly created Orca icon to get the path where the application was installed (in my case C:\Users\ventafri\AppData\Local\Programs\orca\orca.exe).
    • From the plotly\io folder (in my case C:\Users\ventafri\AppData\Local\Programs\Python\Python36\Lib\site-packages\plotly\io) open _orca.py

Substitute:

  # Try to find an executable
   # -------------------------
   # Search for executable name or path in config.executable
   executable = which(config.executable)
   path = os.environ.get("PATH", os.defpath)
   formatted_path = path.replace(os.pathsep, "\n    ")

with:

# Try to find an executable
# -------------------------
# Search for executable name or path in config.executable
executable = r"C:\Users\ventafri\AppData\Local\Programs\orca\orca.exe"
path = os.environ.get("PATH", os.defpath)
formatted_path = path.replace(os.pathsep, "\n    ")
SV125
  • 273
  • 1
  • 3
  • 13
1

As @Eudald mentioned here in Windows to resolve the problem you need to just downgrade plotly-orca to 1.2.1 by:

conda install -c plotly plotly-orca==1.2.1
Mario
  • 1,631
  • 2
  • 21
  • 51
0

I was also able to get orca working by following the procedure described in https://stackoverflow.com/a/59893131/5650199 by KittenCrypto, but for those who are used to installing orca via node.js I thought that I would detail an alternative approach:

sudo apt-get install xvfb
sudo npm install -g electron@6.1.4 orca

Then replace the node installed symlink /usr/local/bin/orca with an xvfb launch script

sudo rm -f /usr/local/bin/orca
printf '#!/bin/bash\nxvfb-run -a /usr/local/lib/node_modules/orca/bin/orca.js "$@"' | sudo tee /usr/local/bin/orca
sudo chmod +x /usr/local/bin/orca

I did this on an Ubuntu 18.04 server with an apt installed python3.7 environment and have tested that static image export works as expected by running:

import pandas as pd
import plotly.express as px

x = [0, 2, 4]
y = [0, 4, 16]
df = pd.DataFrame({'x': x, 'y': y})
fig = px.line(df, x='x', y='y')
fig.write_image('test.png')

Note that the above procedure will work even if you are not running an anaconda python distribution.

  • I found that orca installed another Python version with `npm`. I just removed the other version and it worked. – holzkohlengrill Jun 26 '20 at 08:26
  • Can you add more detail? In my experience npm does not install a configuration that works on a headless server (without manually adding the xvfb-run) – M. Forsythe Jun 27 '20 at 13:36
  • What I mean is that not the curent version of Python is kept but a different version of Python was additionally installed by npm. Possibly a 32 vs 64 bit issue? – holzkohlengrill Jul 02 '20 at 11:42
  • @M.Forsythe, my os is AWS linux AMI (not ubuntu) which has no libgtk2.0-0 & libgconf-2-4 . I followed your approach, tried your example code, got the "fuse: failed to exec fusermount: No such file or directory" error. I also tried (2nd answer on this thread) Haifeng Zhang's approach, got "/usr/bin/xvfb-run: line 166: 0: command not found" error. See also my post https://stackoverflow.com/questions/62639101/plotly-orca-not-working-on-aws-ec2-instance. I run out of idea to try. This orca is so clunky and painful, seems only work on Windows and ubuntu (maybe mac os) only. – ngBeginner Jul 03 '20 at 10:38
  • @ngBeginner I don’t currently have access to an AWS linux system so I can’t help you there, but the fuse error makes it sound like you are having permissions issues on an encrypted volume. Haifeng Zhang’s approach and mine both require having xvfb correctly installed as a pre-requisite. If you are able to use an anaconda distribution of python on you AWS linux distro, that may solve your issue. – M. Forsythe Jul 03 '20 at 13:47
  • @holzohlengrill can you provide more detail about what OS you are on, whether it’s a headless server, and exactly what you did? – M. Forsythe Jul 03 '20 at 13:49
  • @M.Forsythe, I have xvfb installed. Installed orca under conda got me the `can't load libgdk_pixbuf-2.0.so.0` error but I can't install `libgtk2.0-0` & `libgconf-2-4` to resolve the error as both are not available on AWS linux. I tried `orca -> orca-1.2.1-x86_64.AppImage` but hit FUSE error. Extracting AppImage to `~/squashfs-root` folder (equivalent to invoking FUSE) and have `orca -> ~/squashfs-root/app/orca`, the error becomes `line 1: squashfs-root/app/orca:: No such file or directory`. I think the error is due to the 2 missing packages not available on AWS linux. – ngBeginner Jul 03 '20 at 23:49
0

I Just solve it

(mac os)

Run following command:

sudo conda install -c plotly plotly-orca
Jaimil Patel
  • 1,301
  • 6
  • 13
  • Hello what version of OSX and conda please? Did you have to install Xvfb, chromium-browser, libgtk2.0-0 & libgconf-2-4 like on ubuntu? I am unable to get orca to run AWS linux AMI (not ubuntu), see my post https://stackoverflow.com/questions/62639101/plotly-orca-not-working-on-aws-ec2-instance. I am out of idea, this orca is clunky and painful. – ngBeginner Jul 03 '20 at 10:45