提问人:Rama 提问时间:6/30/2023 最后编辑:desertnautRama 更新时间:7/3/2023 访问量:3103
wordcloud AttributeError:“TransposedFont”对象没有属性“getbbox”
wordcloud AttributeError: 'TransposedFont' object has no attribute 'getbbox'
问:
我尝试运行以下代码来生成词云。
text = 'word1 word2 word2 word3 word3 word3'
from wordcloud import WordCloud
wordcloud = WordCloud(width=480, height=480).generate(text)
但是我遇到了这个错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-17-659d2fbc8555> in <module>
8
9 # Generate the word cloud
---> 10 wordcloud.generate(text)
11
12 # Display the word cloud
~\anaconda3\lib\site-packages\wordcloud\wordcloud.py in generate(self, text)
637 self
638 """
--> 639 return self.generate_from_text(text)
640
641 def _check_generated(self):
~\anaconda3\lib\site-packages\wordcloud\wordcloud.py in generate_from_text(self, text)
619 """
620 words = self.process_text(text)
--> 621 self.generate_from_frequencies(words)
622 return self
623
~\anaconda3\lib\site-packages\wordcloud\wordcloud.py in generate_from_frequencies(self, frequencies, max_font_size)
451 font_size = self.height
452 else:
--> 453 self.generate_from_frequencies(dict(frequencies[:2]),
454 max_font_size=self.height)
455 # find font sizes
~\anaconda3\lib\site-packages\wordcloud\wordcloud.py in generate_from_frequencies(self, frequencies, max_font_size)
506 font, orientation=orientation)
507 # get size of resulting text
--> 508 box_size = draw.textbbox((0, 0), word, font=transposed_font, anchor="lt")
509 # find possible places using integral image:
510 result = occupancy.sample_position(box_size[3] + self.margin,
~\anaconda3\lib\site-packages\PIL\ImageDraw.py in textbbox(self, xy, text, font, anchor, spacing, align, direction, features, language, stroke_width, embedded_color)
565 font = self.getfont()
566 mode = "RGBA" if embedded_color else self.fontmode
--> 567 bbox = font.getbbox(
568 text, mode, direction, features, language, stroke_width, anchor
569 )
AttributeError: 'TransposedFont' object has no attribute 'getbbox'
这是我在 jupyter 笔记本中运行代码时获得的完整错误跟踪。
这个错误是什么,如何解决?当我没有在函数中使用该名称的任何参数时,我不明白那是什么。TransposedFont
WordCloud
答:
2赞
Wayne
7/3/2023
#1
解决方案是升级和 ,基于 GitHub 上发布的问题。
请参阅上面帖子下方的评论,了解它如何解决此处的错误。pip
pillow
评论
%
pip install
%pip install --upgrade Pillow
pip install --upgrade numpy