Plotly缺少orca

16

当我使用plotly导出静态图表时,遇到了一些小问题。

Plotly没有正确地识别出我已经安装了orca,我仍然遇到了与缺失orca相关的错误。我尝试更改orca目录,但仍然无法正常工作。有人知道是什么问题吗?

我的代码:

import plotly.graph_objects as go
import orca
import plotly

#%%
fig = go.Figure(data=go.Candlestick(x=pricedata.index,
                    open=pricedata['bidopen'],
                    high=pricedata['bidhigh'],
                    low=pricedata['bidlow'],
                    close=pricedata['bidclose']),)
#%%
fig.show()

#%%
plotly.io.orca.config.executable = r'C:\Users\Kuba\AppData\Local\Programs\Python\Python37\Lib\site-packages\orca'
plotly.io.orca.config.save()

#%%

fig.write_image("images/fig1.png")

这里描述了如何解决它,但对我无效:

https://plot.ly/python/orca-management/#configuring-the-executable

orca版本是1.5.1

谢谢。

B.

编辑:

错误信息:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
c:\Users\Kuba\Documents\GitHub\frstalg\FXCM Stuff\LiveMyStrategyNOTEBOOK-20191017.py in 
      1 
----> 2 fig.write_image("images/fig1.png")

~\AppData\Local\Programs\Python\Python37\lib\site-packages\plotly\basedatatypes.py in write_image(self, *args, **kwargs)
   2686         import plotly.io as pio
   2687 
-> 2688         return pio.write_image(self, *args, **kwargs)
   2689 
   2690     # Static helpers

~\AppData\Local\Programs\Python\Python37\lib\site-packages\plotly\io\_orca.py in write_image(fig, file, format, scale, width, height, validate)
   1703     # Do this first so we don't create a file if image conversion fails
   1704     img_data = to_image(
-> 1705         fig, format=format, scale=scale, width=width, height=height, validate=validate
   1706     )
   1707 

~\AppData\Local\Programs\Python\Python37\lib\site-packages\plotly\io\_orca.py in to_image(fig, format, width, height, scale, validate)
   1480     # Make sure orca sever is running
   1481     # -------------------------------
-> 1482     ensure_server()
   1483 
   1484     # Handle defaults

~\AppData\Local\Programs\Python\Python37\lib\site-packages\plotly\io\_orca.py in ensure_server()
   1342     # Validate orca executable
   1343     if status.state == "unvalidated":
-> 1344         validate_executable()
   1345 
   1346     # Acquire lock to make sure that we keep the properties of orca_state

~\AppData\Local\Programs\Python\Python37\lib\site-packages\plotly\io\_orca.py in validate_executable()
   1041                 executable=config.executable,
   1042                 formatted_path=formatted_path,
-> 1043                 instructions=install_location_instructions,
   1044             )
   1045         )

ValueError: 
The orca executable is required to export figures as static images,
but it could not be found on the system path.

Searched for executable 'C:\Users\Kuba\AppData\Local\Programs\Python\Python37\Lib\site-packages\orca' on the following path:
    C:\Users\Kuba\AppData\Local\Programs\Python\Python37\lib\site-packages
    C:\Program Files\Microsoft MPI\Bin\
    C:\Program Files (x86)\Common Files\Oracle\Java\javapath
    C:\Program Files (x86)\Intel\iCLS Client\
    C:\Program Files\Intel\iCLS Client\
    C:\Windows\system32
    C:\Windows
    C:\Windows\System32\Wbem
    C:\Windows\System32\WindowsPowerShell\v1.0\
    C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
    C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL
    C:\Program Files\Intel\Intel(R) Management Engine Components\DAL
    C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT
    C:\Program Files\Intel\Intel(R) Management Engine Components\IPT
    C:\WINDOWS\system32
    C:\WINDOWS
    C:\WINDOWS\System32\Wbem
    C:\WINDOWS\System32\WindowsPowerShell\v1.0\
    C:\WINDOWS\System32\OpenSSH\
    C:\Program Files\Git\cmd
    C:\Program Files\dotnet\
    C:\Program Files\PuTTY\
    C:\Users\Kuba\AppData\Local\Programs\Python\Python37\Scripts\
    C:\Users\Kuba\AppData\Local\Programs\Python\Python37\
    C:\Users\Kuba\AppData\Local\Microsoft\WindowsApps
    C:\Users\Kuba\AppData\Local\Programs\Microsoft VS Code\bin
    C:\Users\Kuba\AppData\Local\GitHubDesktop\bin
    %USERPROFILE%\AppData\Local\Microsoft\WindowsApps

    C:\Users\Kuba\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\.libs

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

错误信息是什么? - DrBwts
我编辑了原始帖子。 - sixplus4iszen
9个回答

12

1
谢谢,我试图使用Orca,但是那真是一场噩梦。 - Samuel O.D.

9

试试Kaleido,它对我很有效。它是orca的替代品。

conda install -c plotly python-kaleido

6
!pip install plotly==4.7.1
!wget https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1- 
x86_64.AppImage -O /usr/local/bin/orca
!chmod +x /usr/local/bin/orca
!apt-get install xvfb libgtk2.0-0 libgconf-2-4
import plotly.graph_objects as go

fig.show()
fig.write_image("figname.png")#change format if needed

fig.show()
fig.write_image("gdrive/My Drive/destinationfolder/figname.png")

使用Colab或其他工具无法实现Kaleido吗? - william_grisaitis

5
在Windows上,我使用Pycharm和Python 3.6,方法如下:
  • 按照 https://github.com/plotly/orca#installation - 方法4:独立二进制文件:

    • https://github.com/plotly/orca/releases 下载windows-release.zip
    • 安装可执行文件
    • 右键单击新创建的Orca图标,在弹出菜单中选择属性以获取应用程序安装路径。
  • 从 plotly\io 文件夹(在我的情况下是 C:\Users\ventafri\AppData\Local\Programs\Python\Python36\Lib\site-packages\plotly\io)打开 _orca.py

替换:

 # 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    ")

使用:

# 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    ")

抱歉回复晚了。你的解决方案对我没有用,但我找到了一个解决方法,使用 fig.to_html(),然后我可以打开并查看图表,随后转换为图片。也许你的解决方案适用于其他人。 - sixplus4iszen
我在安装orca和plotly的PyCharm上遇到了这个问题,这个解决方案在那里完美地工作。 - Andreas_B
我正在运行以下代码: C:\WINDOWS\system32>orca graph "{ "data": [{"y": [1,2,1]}] }" -o fig.png,但什么也没发生。有任何想法吗? - Mark

4

苏珊娜的答案可能更好一些,但是对我有用的是降级到orca 1.2.1:

conda remove plotly plotly-orca
conda install -c plotly plotly-orca==1.2.1

1
我成功的方法是直接从Github上安装.exe文件:https://github.com/plotly/orca/releases 然后使用新创建的.exe文件的文件路径运行它。
import plotly

plotly.io.orca.config.executable = '...../orca/orca.exe'

0

我在尝试使用非基本conda环境的内核在jupyter笔记本中生成静态图像时,遇到了类似的问题。

我不得不在基本环境中安装plotly-orca才能使它正常工作。


0

-1
如果您仍然遇到依赖问题,可能安装pip install urbansim可以解决它。

2
这个答案应该是一个注释! - nigel239

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接