python3可视化-pyecharts可视化图形库的安装和使用,ImportError: cannot import name ‘Bar‘ from ‘pyecharts‘问题解决
1.pyecharts简介:
利用pyecharts可以制作可视化图形,是非常方便的。而且,该库一直在不断更新,文档非常详细,而且有中文文档,demo例程也非常丰富。
网址:https://github.com/pyecharts/pyecharts
API文档与示例:https://pyecharts.org/#/zh-cn/
2. 安装:
参考官方文档:https://github.com/pyecharts/pyecharts
即:
pip install pyecharts -U
也可以利用下面的命令进行安装:
pip install pyecharts
#pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyecharts #清华资源
安装过程中,出现了错误:
Installing collected packages: MarkupSafe, jinja2, wcwidth, prettytable, simplejson, pyecharts
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied
解决方法,用
pip install pyecharts --user
即可,更详细的错误信息,请移步至:
https://blog.csdn.net/liranke/article/details/119817780
2. Bar模块找不到的问题解决:
安装成功后,运行demo程序,可能出现Bar模块找不到的错误:
ImportError: cannot import name ‘Bar‘ from ‘pyecharts‘
解决方式:
官方文档中明确说了,对于pyecharts,有两个版本,分别是:v0.5.x 和 V1 ,而且二者不兼容,V1 是一个全新的版本。
所以,根据不同的版本,引用的库的方式也略有不同。如果用新版本,就用pyecharts.charts; 如果坚持用旧版本,就去安装旧版本。下面,分别说明:
1)这可能是因为pyecharts新就版本的引用方式有些差别,而且pyecharts的作者已经不再维护旧版本了:
#from pyecharts import Bar #error, 这是旧版本的写法
from pyecharts.charts import Bar #success,这是新版本的写法
2)另外一种解决方法是,用旧的库,即0.1.9.4版本:
pip install pyecharts==0.1.9.4
切勿嵌入版本不匹配的深渊。
还没有评论,来说两句吧...