git上的下载地址:https://github.com/ehmatthes/pcc
个人百度云盘下载地址链接:https://pan.baidu.com/s/1wyK0C6iSS2MrX4bWmqr9tw 提取码:c6so
书中 16.2 制作世界人口地图:JSON格式 中的一些问题:
① from pygal.i18n import COUNTRIES 报异常:ModuleNotFoundError: No module named 'pygal.i18n'
解决方法:
pip install pygal_maps_world
然后使用 from pygal_maps_world.i18n import COUNTRIES 替换 from pygal.i18n import COUNTRIES
例如:
# -*- coding: utf-8 -*-
# from pygal.i18n import COUNTRIES
from pygal_maps_world.i18n import COUNTRIES
def get_country_code(country_name) :
for code, name in COUNTRIES.items() :
if country_name == name :
return code
return None
if __name__ == "__main__" :
print(get_country_code("Andorra"))
print(get_country_code("Afghanistan"))
② wm = pygal.Worldmap() 报异常:AttributeError: module 'pygal' has no attribute 'Worldmap'
解决方法:
使用 wm = pygal.maps.world.World() 替换 wm = pygal.Worldmap()
例如:
# -*- coding: utf-8 -*-
import json
import pygal
from country_codes import get_country_code
# wm = pygal.Worldmap()
wm = pygal.maps.world.World()
wm.title = "North, Central, and South America"
wm.add("North America", ['ca','mx','us'])
wm.add("Central", ['bz','cr','gt','hn','ni','pa','sv'])
wm.add("South America", ['ar','bo','br','cl','co','ec','gf','gy','pe','py','sr','uy','ve'])
wm.render_to_file("americas.svg")