adcode
adcode copied to clipboard
pyecharts1.0版本的怎么解决cannot import name 'Geo' from 'pyecharts'
方法一 :: 降低版本: pip install 'pyecharts<1'
方法二 :: 使用兼容写法,例如:
def init_geo(title, subtitle, title_color, background_color, title_pos='center', width=1200, height=600):
# 兼容新旧版本的pyecharts
try:
from pyecharts.charts import Geo
from pyecharts.options import InitOpts, TitleOpts
from pyecharts.options.series_options import TextStyleOpts
geo = Geo(
init_opts=InitOpts(
width=width,
height=height,
bg_color=background_color,
)
)
geo.set_global_opts(
TitleOpts(
title=title,
subtitle=subtitle,
text_align=title_pos,
title_textstyle_opts=TextStyleOpts(color=title_color),
)
)
return geo
except ImportError:
from pyecharts import Geo
return Geo(
title,
subtitle,
title_color=title_color,
background_color=background_color,
title_pos=title_pos,
width=width,
height=height,
)