赞
踩
#GovRptWordCloudv1.py
import jieba
import wordcloud
from scipy.misc import imread
mask = imread("fivestart.png")
f = open("新时代中国特色社会主义.txt", "r", encoding = "utf-8")
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)
w = wordcloud.WordCloud(font_path = "msyh.ttc", mask = mask, width = 1000, height = 700, background_color = "white")
w.generate(txt)
w.to_file("grwordcloud.png")
ImportError: cannot import name 'imread' from 'scipy.misc'
scipy已经将imread等命令删除,官方文档中有说明
“Functions from scipy.interpolate (spleval, spline, splmake, and spltopp) and functions from scipy.misc (bytescale, fromimage, imfilter, imread, imresize, imrotate, imsave, imshow, toimage) have been removed. The former set has been deprecated since v0.19.0 and the latter has been deprecated since v1.0.0. ”
我们需要换其他的库使用
如使用另一个库imageio
import imageio
imageio.imread()
如果没安要先安一下
#GovRptWordCloudv1.py
import jieba
import wordcloud
import imageio
mask = imageio.imread("fivestart.png")
f = open("新时代中国特色社会主义.txt", "r", encoding = "utf-8")
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)
w = wordcloud.WordCloud(font_path = "msyh.ttc", mask = mask, width = 1000, height = 700, background_color = "white")
w.generate(txt)
w.to_file("grwordcloud.png")
再运行下代码就没问题了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。