Short version
When in Spyder, if I run a script more than once that saves a map with pygal's render_to_file
, I get a TypeError
. It works fine the first time.
Detailed version
I'm trying to save a map using pygal (2.4.0) in Python 3.6 as follows:
from pygal.maps.world import World
worldmap = World()
worldmap.add('Random Places', ['mx', 'bz', 'ru', 'th', 'et'])
worldmap.render_to_file('random_places.svg')
It works fine when I run from the terminal as many times as I want (I'm on Ubuntu). It also works fine when I run it the first time from Spyder (3.2), using F5. Strangely, when I then try to run the code again in Spyder, after it has already run once and worked, the last line throws a TypeError
. It creates an empty file random_places.svg
, but stops there.
It will only run without error again if I restart the kernel (Consoles -> Restart kernel). Note also, if I run the above script, but add a second call to render_to_file
, it also works fine (so it isn't as if the first call is somehow corrupting things).
Here is the traceback:
File "/home/neuronet/SO_pygal_spyder", line 21, in <module>
worldmap.render_to_file('random_places.svg')
File "/home/neuronet/.local/lib/python3.6/site-packages/pygal/graph/public.py", line 114, in render_to_file
f.write(self.render(is_unicode=True, **kwargs))
File "/home/neuronet/.local/lib/python3.6/site-packages/pygal/graph/public.py", line 52, in render
self.setup(**kwargs)
File "/home/neuronet/.local/lib/python3.6/site-packages/pygal/graph/base.py", line 185, in setup
self.state = State(self, **kwargs)
File "/home/neuronet/.local/lib/python3.6/site-packages/pygal/state.py", line 35, in __init__
merge(self.__dict__, graph.config.__class__.__dict__)
File "/home/neuronet/.local/lib/python3.6/site-packages/pygal/util.py", line 384, in merge
dict1[key] = mergextend(val, dict1.get(key, ()))
File "/home/neuronet/.local/lib/python3.6/site-packages/pygal/util.py", line 370, in mergextend
if list1 is None or _ellipsis not in list1:
TypeError: argument of type 'Key' is not iterable
Related questions
来源:https://stackoverflow.com/questions/45419033/cannot-render-to-file-in-pygal-more-than-once-in-spyder