import wordcloud with open('python二级考试大纲.txt',encoding='utf-8') as f: text = f.read() w=wordcloud.WordCloud(background_color="white", font_path='SimHei.ttf') w.generate(text) w.to_file("myclound.png")