Plotly.io doesnt see the psutil package even though its installed

2024/10/11 20:25:50

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 snsimport plotly.graph_objects as gofrom plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)from sklearn.preprocessing import QuantileTransformerimport osif not os.path.exists("images"):os.mkdir("images")# import orcaimport plotly.io as pio
pio.orca.config.executable = '/path/to/orca'
pio.orca.ensure_server()import psutil

To which I get:

ValueError                                Traceback (most recent call last)
<ipython-input-89-6e2b31e44303> in <module>25 import plotly.io as pio26 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 psutilInstall using conda:$ conda install psutil

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

The end goal is to be able to safe plotly generated images automatically with fig.write_image("images/fig1.png")

Answer

If you want to save the plotly figure as image.

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

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

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

https://en.xdnf.cn/q/69730.html

Related Q&A

How to get MultiCells in Pyfpdf Side by side?

I am making a table of about 10 cells with headings in them. They will not fit accross the page unless I use multi_cell option. However I cant figure out How to get a multi_cell side by side. When I ma…

Django: Require Checkbox to be ticked to Submit Form

Im creating a form in Django (using ModelForm). There are many checkboxes, and I want to make it so that one of these must be selected in order to submit the form. I dont mean any one checkbox, but on…

Filtering in django rest framework

In my project I use django rest framework. To filter the results I use django_filters backend. There is my code:models.pyfrom django.db import modelsclass Region(models.Model):name = models.CharField(m…

Efficiency difference between dict.has_key and key in dict in Python [duplicate]

This question already has answers here:Closed 11 years ago.Possible Duplicate:has_key() or in? In Python, therere two ways of deciding whether a key is in a dict:if dict.has_key(key) and if key in di…

python points to global installation even after virtualenv activation

Its a bit weird, I have activated the virtual environment python still points to the global installation.$ which python /usr/bin/python$ source ~/virtualenv/bin/activate (virtualenv)$ which python /usr…

Should I perform both lemmatization and stemming?

Im writing a text classification system in Python. This is what Im doing to canonicalize each token:lem, stem = WordNetLemmatizer(), PorterStemmer() for doc in corpus:for word in doc:lemma = stem.stem(…

Python monkey patch private function

I have a module with a function (call it a()) that calls another function defined in the same module (call it __b()). __b() is a function which speaks to a website via urllib2 and gets some data back.…

How to interleave numpy.ndarrays?

I am currently looking for method in which i can interleave 2 numpy.ndarray. such that>>> a = np.random.rand(5,5) >>> print a [[ 0.83367208 0.29507876 0.41849799 0.58342521 0.818…

Object is not subscripable networkx

import itertools import copy import networkx as nx import pandas as pd import matplotlib.pyplot as plt #-- edgelist = pd.read_csv(https://gist.githubusercontent.com/brooksandrew /e570c38bcc72a8d1024…

WTForms : How to add autofocus attribute to a StringField

I am rather new to WTForms, Flask-WTF. I cant figure out how to simply add the HTML5 attribute "autofocus" to one of the form field, from the form definition. I would like to do that in the P…