word_cloud: ValueError: Only supported for TrueType fonts
Please note: This issue is happening only in windows 10 enviornment.
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# Sample text data
text_data = "Your text data goes here"
# Specify the font path
font_path = './arial.ttf'
# Create a WordCloud object with the font path specified
wordcloud = WordCloud(font_path=font_path).generate(text_data)
# Display the word cloud using matplotlib
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()
Above code when ran in jupyter notebook on windows enviornment produces the following error:
F:\anaconda3\lib\site-packages\PIL\ImageDraw.py in textbbox(self, xy, text, font, anchor, spacing, align, direction, features, language, stroke_width, embedded_color)
649 font = self.getfont()
650 if not isinstance(font, ImageFont.FreeTypeFont):
--> 651 raise ValueError("Only supported for TrueType fonts")
652 mode = "RGBA" if embedded_color else self.fontmode
653 bbox = font.getbbox(
ValueError: Only supported for TrueType fonts
As others suggested to upgrade pillow, this doesn’t solve the problem on windows. Pillow version is 9.5.0, python- 3.10.0. Anaconda Environment Restarted. Windows Restarted. Double checked that font file exists and is font.ttf. Still the problem is not solved.
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 33
Dear friend, I use this code solve it
Linux, anaconda
Running these 2 lines solved the same ‘TrueType font+’ problem for another package - ydata-profiling
pip install --upgrade Pillow
Did the trick for me!
In my case installing the suggested lines worked (after restarting Jupyter Notebook)
Using Python 3.6, re-installed wordcloud 1.8.0 (pip install wordcloud==1.8.0) , issue fixed. Latest version of WordCloud does not support Python3.6 as per official docs.
I tried everything in this comment thread and still facing the same issue: pip install --upgrade pip, pip install --upgrade Pillow, re-installed wordcloud 1.8.0 (pip install wordcloud==1.8.0), Shut down my kernel and restarted the notebook again.
I am using Python 3.8.8 on MacOS. If anyone can help me, it would be appreciated!
pip install --upgrade pip
pip install --upgrade Pillow
I’m a windows user (Windows 10). This worked for me. But I had to restart Jupyter notebooks after installing both of them
i tried the pip and pillow upgrade nothing seems working. i am using python 3.9 version i am still getting the error ;i dont think its a code bug issue AttributeError: ‘TransposedFont’ object has no attribute ‘getbbox’
pip install --upgrade Pillow
This might work and has worked for me while using ydata profling , etc
Hey folks, has anyone solved this issue? I got the same error