简体   繁体   English

用python定位lib Orca

[英]locate lib Orca with python

I´m trying to export the plot into a jpg file.我正在尝试将绘图导出到 jpg 文件中。 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.我遇到的问题是 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. ValueError:需要 orca 可执行文件才能将图形导出为静态图像,但在“/opt/conda/bin/orca”中找到的可执行文件似乎不是有效的 plotly orca 可执行文件。 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:如果您还没有安装 orca,您可以使用 conda 安装,如下所示:

$ conda install -c plotly plotly-orca

Alternatively, see other installation methods in the orca project README at https://github.com/plotly/orca .或者,在https://github.com/plotly/orca的 orca 项目 README 中查看其他安装方法。

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.如果您已经安装了 orca,那么由于某种原因 plotly.py 无法找到它。 In this case, set the plotly.io.orca.config.executable property to the full path of your orca executable.在这种情况下,将plotly.io.orca.config.executable属性设置为 orca 可执行文件的完整路径。 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如果您仍然遇到问题,请随时在论坛上寻求帮助,网址为https://community.plot.ly/c/api/python

Here is the error that was returned by the command $ /opt/conda/bin/orca --help这是命令 $ /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 [返回代码:127] /opt/conda/lib/orca_app/orca:加载共享库时出错:libXtst.so.6:无法打开共享对象文件:没有这样的文件或目录

Note: When used on Linux, orca requires an X11 display server, but none was detected.注意:在 Linux 上使用时,orca 需要 X11 显示服务器,但没有检测到。 Please install X11, or configure your system with Xvfb.请安装 X11,或使用 Xvfb 配置您的系统。 See the orca README ( https://github.com/plotly/orca ) for instructions on using orca with Xvfb.有关将 orca 与 Xvfb 一起使用的说明,请参阅 orca 自述文件 ( https://github.com/plotly/orca )。

Anyone know how to fix this error?任何人都知道如何解决这个错误?

I had to invest significant effort in order to get Orca to work on Ubuntu 18 in my Django 2 project.为了让 Orca 在我的 Django 2 项目中的 Ubuntu 18 上运行,我不得不投入大量精力。 Here is what I did that finally worked:这是我所做的,终于奏效了:

I did this on Ubuntu 18.04.3 LTS我在 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"在下面假设您的用户名为 USERNAME 并且您的虚拟环境目录名为“myvenv”

  1. Get the Orca AppImage file to /home/USERNAME/myvenv/bin and change the rights on the file将 Orca AppImage 文件获取到 /home/USERNAME/myvenv/bin 并更改文件的权限

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 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:在 /home/USERNAME/myvenv/bin/ 中创建一个名为orca的文件,内容如下:

#!/bin/bash

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

The solution is on plotly/orca解决方案在plotly/orca

This i what I have done and it solved my issue:这是我所做的,它解决了我的问题:

  1. Download orca-1.2.1-x86_64.AppImage下载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*通过ln -s orca-1.2.1-x86_64.AppImage orca一个软链接,然后你会看到orca -> orca-1.2.1-x86_64.AppImage*

  3. create a file and name it orca-executable.sh and its content is创建一个文件并将其命名为orca-executable.sh其内容为

    #!/bin/bash #!/bin/庆典

    xvfb-run -a orca "$@" xvfb-run -a 逆戟鲸“$@”

Then add below line into your script然后将以下行添加到您的脚本中

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

Files under path /path/to/orca :路径/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*

What worked for me on Windows is:在 Windows 上对我有用的是:

  • Following https://github.com/plotly/orca#installation - Method 4: Standalone binaries:按照https://github.com/plotly/orca#installation - 方法 4:独立二进制文件:

    • Download windows-release.zip from https://github.com/plotly/orca/releaseshttps://github.com/plotly/orca/releases下载 windows-release.zip
    • 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 ).右键单击桌面上新创建的 Orca 图标以获取安装应用程序的路径(在我的例子中是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从 plotly\io 文件夹(在我的例子中是C:\Users\ventafri\AppData\Local\Programs\Python\Python36\Lib\site-packages\plotly\io )打开_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    ")

As @Eudald mentioned here in Windows to resolve the problem you need to just downgrade plotly-orca to 1.2.1 by:正如@Eudald在 Windows 中提到的,要解决您需要通过以下方式将plotly-orca降级到 1.2.1 的问题:

conda install -c plotly plotly-orca==1.2.1

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:我也能够按照 KittenCrypto 在https://stackoverflow.com/a/59893131/5650199中描述的过程让 orca 工作,但对于那些习惯于通过 node.js 安装 orca 的人,我想我会详细说明替代方法:

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然后用 xvfb 启动脚本替换节点安装的符号链接/usr/local/bin/orca

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:我在安装了 apt python3.7 环境的 Ubuntu 18.04 服务器上执行了此操作,并通过运行测试了静态图像导出是否按预期工作:

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.请注意,即使您没有运行 anaconda python 发行版,上述过程也会起作用。

I Just solve it我只是解决它

(mac os) (苹果系统)

Run following command:运行以下命令:

sudo conda install -c plotly plotly-orca

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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