1

I am having trouble in saving a plotly figure (graph) to disk in python. I am following this example which is on the website https://plot.ly/python/static-image-export/ but every time when i run the code, i am getting this error

ValueError: Image generation requires the psutil package.

Install using pip: $ pip install psutil

I have psutil installed on my machine, its show when i run pip freeze

(dev) workstation:~$ pip freeze | grep psu

psutil==5.7.0

Here is a simple graph i am trying to save

import plotly.graph_objects as go
import numpy as np
np.random.seed(1)

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_trace(go.Scatter(
    x=x,
    y=y,
    mode="markers",
    marker=go.scatter.Marker(
        size=sz,
        color=colors,
        opacity=0.6,
        colorscale="Viridis"
    )
))

fig.write_image("fig1.jpeg")

Would appreciate help. Thank you!

Platform

Ubuntu 16.04

python3.7

shahidammer
  • 1,026
  • 2
  • 10
  • 24
  • Have you installed all dependencies as listed in https://plot.ly/python/static-image-export/, not just `psutil`? If so, can you add `import psutil` on top of your code, and see if it imports succesfully? – Jussi Nurminen Feb 26 '20 at 12:57
  • Yes, I have installed all of the mentioned dependencies, and import psutil does not throw any error – shahidammer Feb 26 '20 at 13:02
  • 1
    Which platform are you on? It works fine for me on Windows 10, but I found people complaining about the same issue: https://stackoverflow.com/questions/53700638/requirement-already-satisfied-with-psutil, https://stackoverflow.com/questions/35621808/no-such-module-psutil-even-though-psutil-is-installed https://stackoverflow.com/questions/58957131/plotly-io-doesnt-see-the-psutil-package-even-though-its-installed Don't really see any definite answers though. – Jussi Nurminen Feb 26 '20 at 13:11
  • I am on ubuntu 16 and python3.7. I should add this in the query, thanks – shahidammer Feb 26 '20 at 13:50
  • 2
    I solved this by simply restarting the kernel (after also installing all the other dependencies as per the docs with `conda install -c plotly plotly-orca==1.2.1 psutil requests`, but that probably wasn't the culprit) – glS May 05 '20 at 21:10
  • I would also add that a restart of the kernel did the trick for me too. Simply installing the dependencies and importing didn't work for me. – Jonathan Dunne Nov 15 '22 at 14:30

0 Answers0