首先创建了一个简单的py项目;
#wordcloud.py import wordcloud c=wordcloud.WordCloud() c.generate("wordcloud by python") c.to_file("pyworldcloud.png")
编译报错:
Traceback (most recent call last): File "E:/1/python/file/wordcloud.py", line 7, in <module> import wordcloud File "E:/1/python/file\wordcloud.py", line 9, in <module> w=wordcloud.WordCloud(AttributeError: module ‘wordcloud‘ has no attribute ‘WordCloud‘ >>>
——解决办法CSDN:
https://blog.csdn.net/BeautyJingJing/article/details/80306731
文件名不可与wordcloud相同,将文件名改为
#wcloud1.py
运行编译,出现错误提示:
Traceback (most recent call last): File "E:/1/python/file/wcloud1.py", line 3, in <module> c=wordcloud.WordCloud() File "C:\Users\26408\AppData\Local\Programs\Python\Python37\lib\site-packages\wordcloud\wordcloud.py", line 300, in __init__ import matplotlib ModuleNotFoundError: No module named ‘matplotlib‘ >>>
估计为为安装第三方库matplotlib;
——解决方法CSDN:
https://blog.csdn.net/dongyanwen6036/article/details/78290878
在cmd下安装第三方库:
D:\myLib>pip install wordcloud
编译运行,打开项目所在文件夹:
出现图片:
pyworldcloud.png
完成;
原文地址:https://www.cnblogs.com/liuxiaoqian17/p/9637159.html
时间: 2024-11-02 00:21:51