File–>Settings–>Project Homework然后再看到下图点击红色框框的加号
然后出现下图,再搜索框搜索wordcloud,然后在左下角那里有个InstallPackage点击等待完成就行,按相同步骤搜索安装imageio就行了
string = '''There are moments in life when you miss someone so much that you just want to pick them from your dreams and hug them for real! Dream what you want to dream;go where you want to go;be what you want to be,because you have only one life and one chance to do all the things you want to do.
May you have enough happiness to make you sweet,enough trials to make you strong,enough sorrow to keep you human,enough hope to make you happy? Always put yourself in others’shoes.If you feel that it hurts you,it probably hurts the other person, too.
The happiest of people don’t necessarily have the best of everything;they just make the most of everything that comes along their way.Happiness lies for those who cry,those who hurt, those who have searched,and those who have tried,for only they can appreciate the importance of people
who have touched their lives.Love begins with a smile,grows with a kiss and ends with a tear.The brightest future will always be based on a forgotten past, you can’t go on well in lifeuntil you let go of your past failures and heartaches.
When you were born,you were crying and everyone around you was smiling.Live your life so that when you die,you're the one who is smiling and everyone around you is crying.
Please send this message to those people who mean something to you,to those who have touched your life in one way or another,to those who make you smile when you really need it,to those that make you see the brighter side of things when you are really down,to those who you want to
let them know that you appreciate their friendship. And if you don’t, don’t worry,nothing bad will happen to you,you will just miss out on the opportunity to brighten someone’s day with this message.'''
from wordcloud import WordCloud
import imageio
prossed_string=string.replace(r'\W',' ')#将上面的string处理,用空格代替各种标点符号,这是正则的用法,匹配非字母和非数字,r是取消转义
bg_pic=imageio.imread('QQ.png')#QQ.png是网图,是你希望做成词云的模版
wordcloud = WordCloud(mask=bg_pic , background_color='black').generate(prossed_string)
wordcloud.to_file('1.jpg')#1.jpg这是生成的词云效果图,运行程序后自动生成,你随意命名,这里我命名为1.jpg
image_produce = wordcloud.to_image()
image_produce.show()
我这个py文件名为统计单词数量.py,在同一目录下还要有素材
代码里有注释,大家看一下
准备好后运行这个py文件就会自动生成名为1.jpg的图片了
现在文件夹里多了个文件
这样就完成了!觉得有帮助的小伙伴点个赞哦~~