gmaps
gmaps copied to clipboard
bad escape \u at position 0?
I'm using just the basic sample code for a marker with popup info test, and the two lines which were given in documentation for exporting to html. I get this output:
Traceback (most recent call last):
File "C:\Python37\lib\sre_parse.py", line 1021, in parse_template
this = chr(ESCAPES[this][1])
KeyError: '\\u'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\saman\Documents\ancestry\python-gedom playground\jupyter-gmaps-test.py", line 31, in <module>
embed_minimal_html('export.html', views=[fig])
File "C:\Python37\lib\site-packages\ipywidgets\embed.py", line 302, in embed_minimal_html
snippet = embed_snippet(views, **kwargs)
File "C:\Python37\lib\site-packages\ipywidgets\embed.py", line 268, in embed_snippet
for view_spec in data['view_specs']
File "C:\Python37\lib\site-packages\ipywidgets\embed.py", line 268, in <genexpr>
for view_spec in data['view_specs']
File "C:\Python37\lib\site-packages\ipywidgets\embed.py", line 241, in escape_script
return script_escape_re.sub(r'\u003c\1', s)
File "C:\Python37\lib\re.py", line 309, in _subx
template = _compile_repl(template, pattern)
File "C:\Python37\lib\re.py", line 300, in _compile_repl
return sre_parse.parse_template(repl, pattern)
File "C:\Python37\lib\sre_parse.py", line 1024, in parse_template
raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \u at position 0
this is the complete code:
from ipywidgets.embed import embed_minimal_html
import gmaps
gmaps.configure(api_key='redacted')
nuclear_power_plants = [
{'name': 'Atucha', 'location': (-34.0, -59.167), 'active_reactors': 1},
{'name': 'Embalse', 'location': (-32.2333, -64.4333), 'active_reactors': 1},
{'name': 'Armenia', 'location': (40.167, 44.133), 'active_reactors': 1},
{'name': 'Br', 'location': (51.217, 5.083), 'active_reactors': 1},
{'name': 'Doel', 'location': (51.333, 4.25), 'active_reactors': 4},
{'name': 'Tihange', 'location': (50.517, 5.283), 'active_reactors': 3}
]
plant_locations = [plant['location'] for plant in nuclear_power_plants]
info_box_template = """
<dl>
<dt>Name</dt><dd>{name}</dd>
<dt>Number reactors</dt><dd>{active_reactors}</dd>
</dl>
"""
plant_info = [info_box_template.format(**plant) for plant in nuclear_power_plants]
marker_layer = gmaps.marker_layer(plant_locations, info_box_content=plant_info)
fig = gmaps.figure()
fig.add_layer(marker_layer)
embed_minimal_html('export.html', views=[fig])
Thanks for raising this. I just ran your example and it worked fine.
Your error looks like it's caused by the Python parser failing to parse the source code. Could this be a copy-paste error where you accidentally pasted an unprintable / unparseable character?
I'll try manually retyping. Thanks for the suggestion.
I have been able to reproduce this by running Python 3.7. I believe the issue is with the underlying ipywidgets embedding code. I will investigate this further.
Re-opening this for the time being.
The underlying ipywidgets issue is referenced here:
https://github.com/jupyter-widgets/ipywidgets/issues/2277
Thanks for continuing to look into this. Please let me know if you find a solution!
For anyone interested in this, I suggest tracking PR 2278 on ipywidgets.
Hi, Thank you for looking into this. I have the same problem and need a solution ASAP. Should I edit the source code as suggested here: https://github.com/jupyter-widgets/ipywidgets/pull/2278? Or downgrade my Python?
Thank you!
I'd recommend using a virtual environment with Python 3.6. I believe IPywidgets has several incompatibilities with Python 3.7 at the moment.
thank you! i will try that. P.S. Possibly not the best place for this comment, but any advice on how to use embed_minimal_html in conjunction with flask? I'm very new to web development.
I would recommend asking that directly in ipywidgets, where any answer is likely to be more useful and seen by more people.
In case someone still hits this issue, installing a fresh version of ipywidgets (>=7.5.0) solved the issue for me on python 3.7.
pip3 install ipywidgets --upgrade
I was hoping upgrading ipywidgets would help, but now there is a different error (ipywidgets-7.5.1):
File "D:\github\shared-taxi\untitled2.py", line 4, in <module>
fig = gmaps.figure()
File "D:\Anaconda3\lib\site-packages\gmaps\figure.py", line 213, in figure
layout=widgets.Layout(width='100%', height='100%')
File "D:\Anaconda3\lib\site-packages\traitlets\traitlets.py", line 958, in __new__
inst.setup_instance(*args, **kwargs)
File "D:\Anaconda3\lib\site-packages\traitlets\traitlets.py", line 986, in setup_instance
super(HasTraits, self).setup_instance(*args, **kwargs)
File "D:\Anaconda3\lib\site-packages\traitlets\traitlets.py", line 977, in setup_instance
value.instance_init(self)
File "D:\Anaconda3\lib\site-packages\traitlets\traitlets.py", line 1692, in instance_init
super(Instance, self).instance_init(obj)
File "D:\Anaconda3\lib\site-packages\traitlets\traitlets.py", line 520, in instance_init
if (self._dynamic_default_callable(obj) is None) \
File "D:\Anaconda3\lib\site-packages\traitlets\traitlets.py", line 504, in _dynamic_default_callable
for cls in mro[:mro.index(self.this_class) + 1]:
ValueError: <class 'ipywidgets.widgets.widget.Widget'> is not in list