Failure at the first hurdle - Python error on "import plotly"

Hi there,

I’ve just started trying to use Plotly (and I’m a bit of a Python novice) following the instructions here: https://plot.ly/python/getting-started/

No errors were reported during installation, but when I try the example:

import plotly
from plotly.graph_objs import Scatter, Layout

plotly.offline.plot({
    "data": [Scatter(x=[1, 2, 3, 4], y=[4, 3, 2, 1])],
    "layout": Layout(title="hello world")
})

I get the error:

[thwill@pseuk1149-centos7-vm]$ python plotly_test.py
Traceback (most recent call last):
  File "plotly_test.py", line 1, in <module>
    import plotly
  File "/usr/lib/python2.7/site-packages/plotly/__init__.py", line 31, in <module>
    from plotly import (plotly, graph_objs, grid_objs, tools, utils, session,
  File "/usr/lib/python2.7/site-packages/plotly/plotly/__init__.py", line 10, in <module>
    from . plotly import (
  File "/usr/lib/python2.7/site-packages/plotly/plotly/plotly.py", line 27, in <module>
    from plotly import exceptions, files, session, tools, utils
  File "/usr/lib/python2.7/site-packages/plotly/tools.py", line 60, in <module>
    matplotlylib = optional_imports.get_module('plotly.matplotlylib')
  File "/usr/lib/python2.7/site-packages/plotly/optional_imports.py", line 23, in get_module
    return import_module(name)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/lib/python2.7/site-packages/plotly/matplotlylib/__init__.py", line 14, in <module>
    from plotly.matplotlylib.renderer import PlotlyRenderer
  File "/usr/lib/python2.7/site-packages/plotly/matplotlylib/renderer.py", line 13, in <module>
    import plotly.graph_objs as go
  File "/usr/lib/python2.7/site-packages/plotly/graph_objs/__init__.py", line 14, in <module>
    from plotly.graph_objs.graph_objs import *  # this is protected with __all__
  File "/usr/lib/python2.7/site-packages/plotly/graph_objs/graph_objs.py", line 34, in <module>
    from plotly import exceptions, graph_reference
  File "/usr/lib/python2.7/site-packages/plotly/graph_reference.py", line 232, in <module>
    @utils.memoize()
  File "/usr/lib/python2.7/site-packages/plotly/utils.py", line 492, in memoize
    return decorator(_memoize)
  File "/usr/lib/python2.7/site-packages/decorator.py", line 213, in decorator
    fun = getfullargspec(callerfunc).args[0] # first arg
IndexError: list index out of range

Using Python 2.7.5 on CentOS 7.

Can anyone help?

Tom

What I have done is this:

import plotly.plotly as plotly

I don’t think that was the problem.

In then end I randomly installed/uninstalled/upgraded various bits of python and generally hit things with a hammer until I got it working … not an explanation that really helps anyone else :frowning:

Hey thwill - I’m running into this error too, and it’s driving me crazy. You ever get any more clues as to what might have been the problem - or at least which packages to upgrade?

Sorry, like I say I messed about a bit, lost interest, then returned and found it was working :wink:

Tom

In case anyone needs this info, I found a solution to this issue as such:
Update pip, then use pip to upgrade the following packages in this order:
cryptography
pyOpen
pyOpenSSL
plotly

I upgraded plotly and I have this issue as well. I was be able to import plotly through my Mac terminal, but encountered error in my Jupyter Notebook. ModuleNotFoundError: No module named ‘plotly’ It has driven me crazy. Any help please?

Hi @hailey_huong,

It’s hard to say for sure, but this can happen if you’re using virtual environments or conda environments and you have the jupyter notebook installed in a separate environment from plotly.

Something else you can try. Run this to display all of the directories where python is searching for modules:

import sys
sys.path

Do this in ipython and in the notebook and see if the paths are different, and if that gives you any clues.

Hope that helps!
-Jon

1 Like

Anyone found out what is going on? i have same issue with plotly.
i have plotly version 3.6.1, python 2.7.4. trying to run --> python robo_graph.py --> running into below error
Traceback (most recent call last):
File “robo_graph.py”, line 4, in
from chart import create_chart
File “/Users//RoboReport/chart.py”, line 1, in
import plotly
ImportError: No module named plotly

Hi @mmsqa ,

Could you check the output of pip list and conda list (if you have conda installed)? First thing I would try is uninstalling it using both, and then install again using either pip or conda.

-Jon