即使安装了 Plotly.io 也看不到 psutil 包 [英] Plotly.io doesn't see the psutil package even though it's installed

查看:118
本文介绍了即使安装了 Plotly.io 也看不到 psutil 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to execute the following code:

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

该软件包已安装,为了以防万一,我也重新安装了它,但一直出现错误.

The package is installed, I reinstalled it just in case as well but keep getting the error.

最终目标是能够使用 fig.write_image("images/fig1.png")

推荐答案

如果您想将绘图图形保存为图像.

If you want to save the plotly figure as image.

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

What worked for me was to install kaleidoand then use the kaleido engine e.g.

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

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

也请参阅以下问题/答案:如何保存plotly express plot转换成 html 或静态图像文件?

see the following question/answer too: How to save plotly express plot into a html or static image file?

这篇关于即使安装了 Plotly.io 也看不到 psutil 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆