cannot import name 'WordCloud' from 'pyecharts' 解决方法

pyecharts 的 WordCloud的使用api

WordCloud.add() 方法签名 
add(name, attr, value, 
shape=”circle”, 
word_gap=20, 
word_size_range=None, 
rotate_step=45) 
name -> str:图例名称 
attr -> list:属性名称 
value -> list:属性所对应的值 
shape -> list:词云图轮廓,有’circle’, ‘cardioid’, ‘diamond’, ‘triangleforward’, ‘triangle’, ‘pentagon’, ‘star’可选 
word_gap -> int:单词间隔,默认为 20。 
word_size_range -> list:单词字体大小范围,默认为 [12, 60]。 
rotate_step -> int:旋转单词角度,默认为 45


 

直接 pip install pyecharts 

from pyecharts import WordCloud

name = [
 'Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World', 'Charter Communications',
 'Chick Fil A', 'Planet Fitness', 'Pitch Perfect', 'Express', 'Home', 'Johnny Depp',
 'Lena Dunham', 'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham',
 'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break']
value = [
 10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112,
 965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265]
wordcloud = WordCloud(width=1000, height=620)
wordcloud.add("", name, value, word_size_range=[20, 80])

wordcloud.render()

报错 cannot import name 'WordCloud' from 'pyecharts'   

pyecharts版本不对,卸载 中心安装指定版本的pyecharts 解决 

 

pip uninstall pyecharts
pip install pyecharts==0.5.11
from pyecharts import WordCloud

name = [
 'Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World', 'Charter Communications',
 'Chick Fil A', 'Planet Fitness', 'Pitch Perfect', 'Express', 'Home', 'Johnny Depp',
 'Lena Dunham', 'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham',
 'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break']
value = [
 10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112,
 965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265]
wordcloud = WordCloud(width=1000, height=620)
wordcloud.add("", name, value, word_size_range=[20, 80])

wordcloud.render()
wordcloud

 执行如图:

cannot import name 'WordCloud' from 'pyecharts' 解决方法_第1张图片

你可能感兴趣的:(python,pip,install,pyecharts,小问题解决)