使用WordCloud包报了如下错误,很明显问题在pillow包上
网上搜了很多法子都解决不了,最后去国外的StackOverflow上找到了解决方法(https://stackoverflow.com/questions/74178079/wordcloud-installation-on-windows-pil-pillow)
Traceback (most recent call last):
File "D:\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3457, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-14-a5239e150765>", line 1, in <module>
wordcloud=wordcloud.generate(text)
File "D:\anaconda3\lib\site-packages\wordcloud\wordcloud.py", line 639, in generate
return self.generate_from_text(text)
File "D:\anaconda3\lib\site-packages\wordcloud\wordcloud.py", line 621, in generate_from_text
self.generate_from_frequencies(words)
File "D:\anaconda3\lib\site-packages\wordcloud\wordcloud.py", line 453, in generate_from_frequencies
self.generate_from_frequencies(dict(frequencies[:2]),
File "D:\anaconda3\lib\site-packages\wordcloud\wordcloud.py", line 503, in generate_from_frequencies
font = ImageFont.truetype(self.font_path, font_size)
File "D:\anaconda3\lib\site-packages\PIL\ImageFont.py", line 959, in truetype
return freetype(font)
File "D:\anaconda3\lib\site-packages\PIL\ImageFont.py", line 956, in freetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "D:\anaconda3\lib\site-packages\PIL\ImageFont.py", line 219, in __init__
if core.HAVE_RAQM:
File "D:\anaconda3\lib\site-packages\PIL\ImageFont.py", line 58, in __getattr__
raise ImportError("The _imagingft C module is not installed")
ImportError: The _imagingft C module is not installed
解决方法:
pip install freetype-py
pip uninstall pillow
pip install --no-cache-dir pillow
成功解决!