Skip to content
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

pyecharts1.0版本的怎么解决cannot import name 'Geo' from 'pyecharts' #5

Open
like-firework opened this issue Mar 9, 2022 · 1 comment

Comments

@like-firework
Copy link

No description provided.

@waketzheng
Copy link

方法一 :: 降低版本: 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,
        )

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

No branches or pull requests

2 participants