报错
OSError: cannot open resource
原代码
wordcloud=WordCloud(font_path="simhei.ttf",background_color="white",max_font_size=80)
出现报错的原因是找不到simhei.ttf
解决方法
首先找到MAC中存放字体的位置
复制你所需要字体的位置,修改如下
wordcloud=WordCloud(font_path="/System/Library/Fonts/simhei.ttf",background_color="white",max_font_size=80)
后面还是报错,仔细一看,发现黑体在MAC下的名字和WINDOWS下的是不一样的,再次修改
wordcloud=WordCloud(font_path="/System/Library/Fonts/STHeiti Medium.ttc",background_color="white",max_font_size=80)
最后运行一遍,成功运行