amueller / word_cloud

A little word cloud generator in Python
https://amueller.github.io/word_cloud
MIT License
10.02k stars 2.31k forks source link

"AttributeError: 'ImageDraw' object has no attribute 'textbbox'" on Ubuntu 20.04 #755

Open nakic opened 6 months ago

nakic commented 6 months ago

Description

wordcloud fails to run due to (apparently) dependency version misalignment, producing the error below:

AttributeError: 'ImageDraw' object has no attribute 'textbbox'

The problem is mentioned in an SO thread, but no reliable solution was proposed.

Steps/Code to Reproduce

$ wordcloud_cli --text /tmp/simple_test_input.txt --imagefile /tmp/out.png
/usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.15) or chardet (3.0.4) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
Traceback (most recent call last):
  File "/home/t/.local/bin/wordcloud_cli", line 8, in <module>
    sys.exit(main())
  File "/home/t/.local/lib/python3.8/site-packages/wordcloud/__main__.py", line 33, in main
    wordcloud_cli_main(*wordcloud_cli_parse_args(sys.argv[1:]))
  File "/home/t/.local/lib/python3.8/site-packages/wordcloud/wordcloud_cli.py", line 90, in main
    wordcloud.generate(text)
  File "/home/t/.local/lib/python3.8/site-packages/wordcloud/wordcloud.py", line 642, in generate
    return self.generate_from_text(text)
  File "/home/t/.local/lib/python3.8/site-packages/wordcloud/wordcloud.py", line 624, in generate_from_text
    self.generate_from_frequencies(words)
  File "/home/t/.local/lib/python3.8/site-packages/wordcloud/wordcloud.py", line 453, in generate_from_frequencies
    self.generate_from_frequencies(dict(frequencies[:2]),
  File "/home/t/.local/lib/python3.8/site-packages/wordcloud/wordcloud.py", line 511, in generate_from_frequencies
    box_size = draw.textbbox((0, 0), word, font=transposed_font, anchor="lt")
AttributeError: 'ImageDraw' object has no attribute 'textbbox'
$

Expected Results

wordcloud runs without any CLI output and produces a PNG with a wordcloud.

Actual Results

See above. Repeatability is 100% out of several attempts on 2 separate machines, both running Ubuntu 20.04.

Versions

import platform; print(platform.platform()) Linux-5.15.0-88-generic-x86_64-with-glibc2.29 import sys; print("Python", sys.version) Python 3.8.10 (default, Nov 22 2023, 10:22:35) [GCC 9.4.0] import numpy; print("NumPy", numpy.version) NumPy 1.17.4 import matplotlib; print("matplotlib", matplotlib.version) matplotlib 3.1.2 import wordcloud; print("wordcoud", wordcloud.version) wordcoud 1.9.3

nakic commented 6 months ago

Just found a workaround:

$ pip remove wordcloud $ pip install wordcloud==1.8.0

After that, works as expected. Also stumbled onto a comment saying that it's known that the latest version doesn't run on python 3.6 (and apparently later). Leaving this here for anyone who stumbles upon the same issue, FWIW.