想用python做个wordcloud但是永远在出错,明明是按照书上的代码敲的
import wordcloud
import jieba
f = open('news.txt')
t = f.read()
f.close()
words = jieba.lcut(t)
txt = ' '.join(words)
w = wordcloud.WordCloud(font_path = r'C:\WINDOWS\Fonts\simhei.ttf',
background_color = 'white')
w.generate(txt)
w.to_file('C:/test.jpg/')
Building prefix dict from the default dictionary ...
Loading model from cache C:\Users\86136\AppData\Local\Temp\jieba.cache
Loading model cost 0.852 seconds.
Prefix dict has been built successfully.
Traceback (most recent call last):
File "C:\Users\86136\AppData\Local\Programs\Python\Python310\lib\site-packages\PIL\Image.py", line 2215, in save
format = EXTENSION[ext]
KeyError: ''
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:/Users/86136/Desktop/w.py", line 25, in
w.to_file('C:/test.jpg/')
File "C:\Users\86136\AppData\Local\Programs\Python\Python310\lib\site-packages\wordcloud\wordcloud.py", line 719, in to_file
img.save(filename, optimize=True)
File "C:\Users\86136\AppData\Local\Programs\Python\Python310\lib\site-packages\PIL\Image.py", line 2217, in save
raise ValueError(f"unknown file extension: {ext}") from e
ValueError: unknown file extension:
没办法我真的不会我是python初学者