#GovRptWordCloud.py
import jieba
import wordcloud
from scipy.misc import imread
mask = imread("fivestart.png")
excludes = { }
f = open("新时代中国特色*.txt", "r", encoding="GBK")
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)
w = wordcloud.WordCloud(\
width = 1000, height = 700,\
background_color = "white",
font_path = "SIMLI", mask = mask
)
w.generate(txt)
w.to_file("grwordcloudm.png")
from scipy.misc import imread
ModuleNotFoundError: No module named 'scipy'
C:\Users\l>python -m pip install -i https://mirrors.aliyun.com/pypi/simple/ --user scipy
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting scipy
Downloading https://mirrors.aliyun.com/pypi/packages/66/80/d8a5050df5b4d8229e018f3222fe603ce7f92
c026b78f4e05d69c3a6c43b/scipy-1.5.2-cp37-cp37m-win_amd64.whl (31.2MB)
|███████████████████████████████▌| 30.6MB 3.3MB/s eta 0:00:01
|███████████████████████████████▌| 30.6MB 3.3MB/s eta 0:00:01
|████████████████████████████████| 31.2MB 3.3MB/s eta 0:00:01
|████████████████████████████████| 31.2MB 469kB/s
Requirement already satisfied: numpy>=1.14.5 in d:\program files\python37\lib\site-packages (from
scipy) (1.19.1)
Installing collected packages: scipy
Successfully installed scipy-1.5.2
from scipy.misc import imread
ImportError: cannot import name 'imread' from 'scipy.misc' (C:\Users\l\AppData\Roaming\Python\Python37\site-packages\scipy\misc\__init__.py)
C:\Users\l>python -m pip install -i https://mirrors.aliyun.com/pypi/simple/ --user scipy==1.1.0
小结:
1.版本要配备,如scipy-1.5.2并找不到相应的库,需要使用scipy-1.1.0才可以;
2.使用国外的镜像非常慢,并有时无法下载,建议使用国内的镜像,例如上述使用阿里云,这样的下载速度非常快;
3.endcoding='utf-8'改变成endcoding='GBK'才可以正常运行;
4. font_path = "SIMLI",需要提供该字体才可以正常运行;
5.程序运行效果图如下: