Skip to content

"config_dict" UnboundLocalError after upgrade to Plotly 3.8.1 #1550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SigmaX opened this issue May 6, 2019 · 3 comments · Fixed by #1551
Closed

"config_dict" UnboundLocalError after upgrade to Plotly 3.8.1 #1550

SigmaX opened this issue May 6, 2019 · 3 comments · Fixed by #1551
Milestone

Comments

@SigmaX
Copy link

SigmaX commented May 6, 2019

After upgrading from 3.7.1 to 3.8.1 (as installed via pip/PyPI), simple plots break with UnboundLocalError: local variable 'config_dict' referenced before assignment.

Minimum working example:

import plotly.graph_objs as go

go.Figure()

Expected behavior: a Figure should be returned.

Figure({
    'data': [], 'layout': {}
})

I'm running macOS and Python 3.7.0. Downgrading to plotly 3.7.1 is a workaround: sudo pip3 install plotly=3.7.1.

Stack trace:

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-1-0c49f1f32fec> in <module>()
      1 import plotly.graph_objs as go
      2 
----> 3 go.Figure()

/usr/local/lib/python3.7/site-packages/plotly/graph_objs/_figure.py in __init__(self, data, layout, frames, skip_invalid)
    501             is invalid AND skip_invalid is False
    502         """
--> 503         super(Figure, self).__init__(data, layout, frames, skip_invalid)
    504 
    505     def add_area(

/usr/local/lib/python3.7/site-packages/plotly/basedatatypes.py in __init__(self, data, layout_plotly, frames, skip_invalid)
    196         # options are compatible with FigureWidget.
    197         from plotly.offline.offline import _get_jconfig
--> 198         self._config = _get_jconfig(None)
    199 
    200         # Frames

/usr/local/lib/python3.7/site-packages/plotly/offline/offline.py in _get_jconfig(config)
    160         clean_config = {}
    161 
--> 162     plotly_platform_url = plotly.tools.get_config_plotly_server_url()
    163 
    164     clean_config['plotlyServerURL'] = plotly_platform_url

/usr/local/lib/python3.7/site-packages/plotly/tools.py in get_config_plotly_server_url()
   1286             data = {}
   1287 
-> 1288     return config_dict.get('plotly_domain', default_server_url)
   1289 
   1290 

UnboundLocalError: local variable 'config_dict' referenced before assignment

I observe the same behavior with more involved go.Figure() calls, such as the following:

import plotly.graph_objs as go
import numpy as np

x = np.arange(0, 1, 0.03)
y = np.arange(0, 1, 0.03)
xx, yy = np.meshgrid(x, y)
f = lambda v: np.array(v[0])**2 + np.array(v[1])**2

@np.vectorize
def v_fun(x, y):
    return f([x, y])

z = v_fun(xx, yy)
trace = [go.Surface(x=x, y=y, z=z, showscale=False)]
fig = go.Figure(data=trace,
                layout=go.Layout(
                    scene={"xaxis": {'title': "", "tickfont": {"size": 10}, 'type': "linear"},
                           "yaxis": {"title": "", "tickfont": {"size": 10},
                                     "tickangle": 1},
                           "zaxis": {'title': "Fitness", "tickfont": {"size": 10}},
                           "aspectratio": {'x': 2.0, 'y': 2.0, 'z': 1.0}
                           }
                ))
@jonmmease
Copy link
Contributor

Thanks a lot for the report @SigmaX, it looks like this error would crop up when the ~/.plotly/.config file is not found or not loaded successfully. #1551 should take care of it.

@jonmmease jonmmease added this to the v3.9.0 milestone May 6, 2019
@jonmmease
Copy link
Contributor

Hi @SigmaX, could you try out the 3.9.0 release candidate and check whether this takes care of the issue for you? installation instructions at https://github.com/plotly/plotly.py/blob/release_3.9.0/README.md#installation.

Thanks!

@SigmaX
Copy link
Author

SigmaX commented May 7, 2019

Works like a charm. Thanks so much for the lightning-fast fix, @jonmmease!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants