【问题标题】:Plotly.io doesn't see the psutil package even though it's installedPlotly.io 没有看到 psutil 包,即使它已安装
【发布时间】:2020-03-16 08:02:56
【问题描述】:

我正在尝试执行以下代码:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
%matplotlib inline
import seaborn as sns

import plotly.graph_objects as go

from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)

from sklearn.preprocessing import QuantileTransformer

import os

if not os.path.exists("images"):
    os.mkdir("images")

# import orca


import plotly.io as pio
pio.orca.config.executable = '/path/to/orca'
pio.orca.ensure_server()

import psutil

我得到的:

ValueError                                Traceback (most recent call last)
<ipython-input-89-6e2b31e44303> in <module>
     25 import plotly.io as pio
     26 pio.orca.config.executable = '/path/to/orca'
---> 27 pio.orca.ensure_server()
     28 
     29 import psutil

~/Library/Python/3.7/lib/python/site-packages/plotly/io/_orca.py in ensure_server()
   1368 Install using conda:
   1369     $ conda install psutil
-> 1370 """
   1371         )
   1372 

ValueError: Image generation requires the psutil package.

Install using pip:
    $ pip install psutil

Install using conda:
    $ conda install psutil

软件包已安装,我重新安装了它以防万一,但一直收到错误。

最终目标是能够使用fig.write_image("images/fig1.png") 自动保护绘图生成的图像

【问题讨论】:

  • 您很可能将软件包安装在不同的环境中。您是否在 conda 虚拟环境中运行代码?
  • 应该是一样的,其他的包都是一样的安装方式:% python3 -m pip install psutil==5.4.8 --user
  • 但是您是在虚拟环境中运行代码吗?
  • 你解决了吗?这也发生在我身上
  • 不幸的是,没有。最后手动保存。因为一旦我以某种方式解决了import psutil,它就开始请求我已经拥有的requests

标签: python plotly psutil plotly-python


【解决方案1】:

如果你想将绘图保存为图像。

对我有用的是安装kaleido然后使用万花筒引擎 例如

pip 安装 Kaleido plotly.io.write_image(fig, 'fig1.jpeg', format='jpeg',validate=False, engine='kaleido')

也请参阅以下问题/答案: How to save plotly express plot into a html or static image file?

【讨论】:

    猜你喜欢
    • 2016-06-07
    • 2020-12-12
    • 1970-01-01
    • 1970-01-01
    • 2017-10-04
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 2011-09-23
    相关资源
    最近更新 更多