Plotly.py: ImportError: cannot import name utils

Created on 14 Feb 2016  路  7Comments  路  Source: plotly/plotly.py

Not able to run Plot.ly because of error:

Traceback:

import plotly
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-35-9c23c5c2643a> in <module>()
      2 import numpy as np
      3 import dateutil
----> 4 import plotly

~/ipython-venv/lib/python2.7/site-packages/plotly/__init__.py in <module>()
     29 from __future__ import absolute_import
     30 
---> 31 from plotly import (plotly, graph_objs, grid_objs, tools, utils, session,
     32                     offline)
     33 from plotly.version import __version__

~/ipython-venv/lib/python2.7/site-packages/plotly/plotly/__init__.py in <module>()
      8 
      9 """
---> 10 from . plotly import (
     11     sign_in,
     12     update_plot_options,

~/ipython-venv/lib/python2.7/site-packages/plotly/plotly/plotly.py in <module>()
     29 from requests.auth import HTTPBasicAuth
     30 
---> 31 from plotly import exceptions, tools, utils, version, files
     32 from plotly.plotly import chunked_requests
     33 from plotly.session import (sign_in, update_session_plot_options,

~/ipython-venv/lib/python2.7/site-packages/plotly/tools.py in <module>()
     16 import math
     17 
---> 18 from plotly import utils
     19 from plotly import exceptions
     20 from plotly import graph_reference

ImportError: cannot import name utils

Requirements.txt:

appnope (0.1.0)
backports-abc (0.4)
backports.ssl-match-hostname (3.5.0.1)
beautifulsoup4 (4.4.1)
brewer2mpl (1.4.1)
certifi (2015.11.20.1)
cycler (0.9.0)
decorator (4.0.9)
functools32 (3.2.3.post2)
ggplot (0.6.8)
gnureadline (6.3.3)
ipykernel (4.2.2)
ipython (4.1.1)
ipython-genutils (0.1.0)
Jinja2 (2.8)
jsonschema (2.5.1)
jupyter-client (4.1.1)
jupyter-core (4.0.6)
MarkupSafe (0.23)
matplotlib (1.5.1)
mechanize (0.2.5)
mistune (0.7.1)
nbconvert (4.1.0)
nbformat (4.0.1)
notebook (4.1.0)
numpy (1.10.4)
pandas (0.17.1)
path.py (8.1.2)
patsy (0.4.1)
pexpect (4.0.1)
pickleshare (0.6)
pip (8.0.2)
plotly (1.9.5)
ptyprocess (0.5.1)
Pygments (2.1.1)
pyparsing (2.1.0)
python-dateutil (2.4.2)
pytz (2015.7)
pyzmq (15.2.0)
requests (2.9.1)
scipy (0.17.0)
selenium (2.52.0)
setuptools (20.1.1)
simplegeneric (0.8.1)
singledispatch (3.4.0.3)
six (1.10.0)
statsmodels (0.6.1)
termcolor (1.1.0)
terminado (0.6)
tornado (4.3)
traitlets (4.1.0)
utils (0.9.0)

Most helpful comment

Okay, I think that I've found something more consistent with this.

If I import matplotlib before trying to import plotly, then the "cannot import name utils" error appears.

If I restart the Python kernel and skip trying to load matplotlib, then the utils error does not appear.

I'm using inotebook and have been trying to figure out why I've been getting the insecure string pickle error with matplotlib, which is why I was trampling on top of other libraries.

All 7 comments

@acer9997 thanks for reporting! what do you mean by install utils separately? utils is referring to a module inside this package (https://github.com/plotly/plotly.py/blob/master/plotly/utils.py) not a separate package.

Sorry - I'm out of sorts this morning! I had two different environments running and didn't realize what I was doing. The error is still appearing. I removed that other misleading comment.

got it, thanks @acer9997 . I'm not sure what's going on here yet

@acer9997 - do you think it could be conflicting with the package that you have installed called utils? In your requirements.txt:

utils (0.9.0)

Thanks again for reporting!

@chriddyp - it could be.

I uninstalled utils and tried importing plotly again, but got a different error that I don't think is related to Plot.ly and has been occurring when trying to import matplotlib in other situations:

ValueError                                Traceback (most recent call last)
<ipython-input-1-576e619f41d1> in <module>()
      3 import dateutil
      4 # from ggplot import *
----> 5 import plotly

~/ipython-venv/lib/python2.7/site-packages/plotly/__init__.py in <module>()
     29 from __future__ import absolute_import
     30 
---> 31 from plotly import (plotly, graph_objs, grid_objs, tools, utils, session,
     32                     offline)
     33 from plotly.version import __version__

~/ipython-venv/lib/python2.7/site-packages/plotly/plotly/__init__.py in <module>()
      8 
      9 """
---> 10 from . plotly import (
     11     sign_in,
     12     update_plot_options,

~/ipython-venv/lib/python2.7/site-packages/plotly/plotly/plotly.py in <module>()
     29 from requests.auth import HTTPBasicAuth
     30 
---> 31 from plotly import exceptions, tools, utils, version, files
     32 from plotly.plotly import chunked_requests
     33 from plotly.session import (sign_in, update_session_plot_options,

~/ipython-venv/lib/python2.7/site-packages/plotly/tools.py in <module>()
     32 
     33 try:
---> 34     from . import matplotlylib
     35     _matplotlylib_imported = True
     36 except ImportError:

~/ipython-venv/lib/python2.7/site-packages/plotly/matplotlylib/__init__.py in <module>()
     12 from __future__ import absolute_import
     13 
---> 14 from plotly.matplotlylib.renderer import PlotlyRenderer
     15 from plotly.matplotlylib.mplexporter import Exporter

~/ipython-venv/lib/python2.7/site-packages/plotly/matplotlylib/renderer.py in <module>()
     12 
     13 import plotly.graph_objs as go
---> 14 from plotly.matplotlylib.mplexporter import Renderer
     15 from plotly.matplotlylib import mpltools
     16 

~/ipython-venv/lib/python2.7/site-packages/plotly/matplotlylib/mplexporter/__init__.py in <module>()
----> 1 from .renderers import Renderer
      2 from .exporter import Exporter

~/ipython-venv/lib/python2.7/site-packages/plotly/matplotlylib/mplexporter/renderers/__init__.py in <module>()
      8 
      9 from .base import Renderer
---> 10 from .vega_renderer import VegaRenderer, fig_to_vega
     11 from .vincent_renderer import VincentRenderer, fig_to_vincent
     12 from .fake_renderer import FakeRenderer, FullFakeRenderer

~/ipython-venv/lib/python2.7/site-packages/plotly/matplotlylib/mplexporter/renderers/vega_renderer.py in <module>()
      3 import random
      4 from .base import Renderer
----> 5 from ..exporter import Exporter
      6 
      7 

~/ipython-venv/lib/python2.7/site-packages/plotly/matplotlylib/mplexporter/exporter.py in <module>()
     10 
     11 import matplotlib
---> 12 from matplotlib import transforms, collections
     13 
     14 

~/ipython-venv/lib/python2.7/site-packages/matplotlib/collections.py in <module>()
     25 import matplotlib.artist as artist
     26 from matplotlib.artist import allow_rasterization
---> 27 import matplotlib.backend_bases as backend_bases
     28 import matplotlib.path as mpath
     29 from matplotlib import _path

~/ipython-venv/lib/python2.7/site-packages/matplotlib/backend_bases.py in <module>()
     60 
     61 import matplotlib.tight_bbox as tight_bbox
---> 62 import matplotlib.textpath as textpath
     63 from matplotlib.path import Path
     64 from matplotlib.cbook import mplDeprecation, warn_deprecated

~/ipython-venv/lib/python2.7/site-packages/matplotlib/textpath.py in <module>()
     13 from matplotlib.path import Path
     14 from matplotlib import rcParams
---> 15 import matplotlib.font_manager as font_manager
     16 from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
     17 from matplotlib.ft2font import LOAD_TARGET_LIGHT

~/ipython-venv/lib/python2.7/site-packages/matplotlib/font_manager.py in <module>()
   1419                 verbose.report("Using fontManager instance from %s" % _fmcache)
   1420         except:
-> 1421             _rebuild()
   1422     else:
   1423         _rebuild()

~/ipython-venv/lib/python2.7/site-packages/matplotlib/font_manager.py in _rebuild()
   1404     def _rebuild():
   1405         global fontManager
-> 1406         fontManager = FontManager()
   1407         if _fmcache:
   1408             pickle_dump(fontManager, _fmcache)

~/ipython-venv/lib/python2.7/site-packages/matplotlib/font_manager.py in __init__(self, size, weight)
   1042         #  Load TrueType fonts and create font dictionary.
   1043 
-> 1044         self.ttffiles = findSystemFonts(paths) + findSystemFonts()
   1045         self.defaultFamily = {
   1046             'ttf': 'Bitstream Vera Sans',

~/ipython-venv/lib/python2.7/site-packages/matplotlib/font_manager.py in findSystemFonts(fontpaths, fontext)
    322                     fontfiles[f] = 1
    323 
--> 324             for f in get_fontconfig_fonts(fontext):
    325                 fontfiles[f] = 1
    326 

~/ipython-venv/lib/python2.7/site-packages/matplotlib/font_manager.py in get_fontconfig_fonts(fontext)
    274         pipe = subprocess.Popen(['fc-list', '--format=%{file}\\n'],
    275                                 stdout=subprocess.PIPE,
--> 276                                 stderr=subprocess.PIPE)
    277         output = pipe.communicate()[0]
    278     except (OSError, IOError):

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
    708                                 p2cread, p2cwrite,
    709                                 c2pread, c2pwrite,
--> 710                                 errread, errwrite)
    711         except Exception:
    712             # Preserve original exception in case os.close raises.

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
   1332                     if e.errno != errno.ECHILD:
   1333                         raise
-> 1334                 child_exception = pickle.loads(data)
   1335                 raise child_exception
   1336 

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc in loads(str)
   1386 def loads(str):
   1387     file = StringIO(str)
-> 1388     return Unpickler(file).load()
   1389 
   1390 # Doctest

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc in load(self)
    862             while 1:
    863                 key = read(1)
--> 864                 dispatch[key](self)
    865         except _Stop, stopinst:
    866             return stopinst.value

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc in load_string(self)
    970             if rep.startswith(q):
    971                 if len(rep) < 2 or not rep.endswith(q):
--> 972                     raise ValueError, "insecure string pickle"
    973                 rep = rep[len(q):-len(q)]
    974                 break

ValueError: insecure string pickle

Okay, I think that I've found something more consistent with this.

If I import matplotlib before trying to import plotly, then the "cannot import name utils" error appears.

If I restart the Python kernel and skip trying to load matplotlib, then the utils error does not appear.

I'm using inotebook and have been trying to figure out why I've been getting the insecure string pickle error with matplotlib, which is why I was trampling on top of other libraries.

Hi @actongorton, I'm going to close this issue for now since plotly.py has been largely rewritten over the last two years, but feel free to open a new issue if you're having similar problems with ploty.py version 3. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gv-collibris picture gv-collibris  路  4Comments

binaryfunt picture binaryfunt  路  5Comments

jonmmease picture jonmmease  路  3Comments

vlizanae picture vlizanae  路  4Comments

aplowman picture aplowman  路  3Comments