Repository: plotly/plotly.py

Issue:
Merely importing plotly 3.6.0 causes error
I've got an issue with plotly version 3.6.0

Running `import plotly` gives me the following error in Spyder 3.2.4:
```
Traceback (most recent call last):

  File "<ipython-input-13-5fb02038c35f>", line 1, in <module>
    import plotly

  File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\__init__.py", line 31, in <module>
    from plotly import (plotly, dashboard_objs, graph_objs, grid_objs, tools,

  File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\plotly\__init__.py", line 10, in <module>
    from . plotly import (

  File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\plotly\plotly.py", line 35, in <module>
    from plotly.graph_objs import Scatter

  File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\graph_objs\__init__.py", line 82, in <module>
    from ._figurewidget import FigureWidget

  File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\graph_objs\_figurewidget.py", line 12, in <module>
    class FigureWidget(BaseFigureWidget):

TypeError: function() argument 1 must be code, not str

Traceback (most recent call last):

  File "<ipython-input-13-5fb02038c35f>", line 1, in <module>
    import plotly

  File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\__init__.py", line 31, in <module>
    from plotly import (plotly, dashboard_objs, graph_objs, grid_objs, tools,

  File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\plotly\__init__.py", line 10, in <module>
    from . plotly import (

  File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\plotly\plotly.py", line 35, in <module>
    from plotly.graph_objs import Scatter

  File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\graph_objs\__init__.py", line 82, in <module>
    from ._figurewidget import FigureWidget

  File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\graph_objs\_figurewidget.py", line 12, in <module>
    class FigureWidget(BaseFigureWidget):

TypeError: function() argument 1 must be code, not str
```


Discussion:
Hi @zeluspudding,

Thanks for the report!  Unfortunately I can't reproduce this. Could you include the versions of python and ipywidgets that you have installed?  My suspicion is that it might have something to do with https://github.com/plotly/plotly.py/pull/1417.

Thanks!

I'm having the same problem as @zeluspudding, attempting to import plotly in a Zeppelin notebook and getting the exact same error. 

I'm running Python 3.6.1 and ipywidgets 6.0.0
Thanks for the info @chornbaker.  

Could you please either uninstall ipywidgets, or upgrade to ipywidgets >= 7.2 and let us know if that takes care of the problem?  Thanks!

Resolving patch:
diff --git a/codegen/__init__.py b/codegen/__init__.py
--- a/codegen/__init__.py
+++ b/codegen/__init__.py
@@ -235,10 +235,13 @@ def perform_codegen():
     optional_figure_widget_import = """
 try:
     import ipywidgets
-    from ._figurewidget import FigureWidget
+    from distutils.version import LooseVersion
+    if LooseVersion(ipywidgets.__version__) >= LooseVersion('7.0.0'):
+        from ._figurewidget import FigureWidget
+    del LooseVersion
+    del ipywidgets
 except ImportError:
     pass
-
 """
     root_datatype_imports.append(optional_figure_widget_import)
 
diff --git a/plotly/basewidget.py b/plotly/basewidget.py
--- a/plotly/basewidget.py
+++ b/plotly/basewidget.py
@@ -15,6 +15,7 @@
 from .serializers import custom_serializers
 from .version import __frontend_version__
 
+
 @widgets.register
 class BaseFigureWidget(BaseFigure, widgets.DOMWidget):
     """
diff --git a/plotly/graph_objs/__init__.py b/plotly/graph_objs/__init__.py
--- a/plotly/graph_objs/__init__.py
+++ b/plotly/graph_objs/__init__.py
@@ -79,10 +79,13 @@
 
 try:
     import ipywidgets
-    from ._figurewidget import FigureWidget
+    from distutils.version import LooseVersion
+    if LooseVersion(ipywidgets.__version__) >= LooseVersion('7.0.0'):
+        from ._figurewidget import FigureWidget
+    del LooseVersion
+    del ipywidgets
 except ImportError:
     pass
-
 from ._deprecations import (
     Data, Annotations, Frames, AngularAxis, Annotation, ColorBar, Contours,
     ErrorX, ErrorY, ErrorZ, Font, Legend, Line, Margin, Marker, RadialAxis,


Test patch: