amueller / word_cloud

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

ValueError: Only supported for TrueType fonts #729

Open talha2k opened 1 year ago

talha2k commented 1 year ago

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.

talha2k commented 1 year ago

I switched from jupyter notebook on my windows 10 machine to google collab enviornment and wordcloud worked there as expected.

I would request to keep this issue open until a resolution is found.

StarDxxx commented 1 year ago

Dear friend, I use this code solve it

pip install --upgrade pip

pip install --upgrade Pillow

Linux, anaconda

JainShubham23 commented 1 year ago

@StarDxxx What python version are you using? This is not working for me.

danielqingz commented 1 year ago

Hey folks, has anyone solved this issue? I got the same error

opgeROBt commented 1 year ago

Had a similar issue (and fix) with an error: AttributeError: 'TransposedFont' object has no attribute 'getbbox'

I saw the pip install of wordcloud included older versions of numpy and Pillow. Just pip installing numpy and pillow above wordcloud (and matplotlib) fixed the issue for me.

edit: working on a databricks cluster

BrokenShell commented 1 year ago

pip install --upgrade Pillow

Did the trick for me!

dbetm commented 1 year ago

I have the same issue, even when I tried the trick of upgrade pip and Pillow

a-ibrahimi commented 1 year ago

Facing the same issue as well and updating PIP and Pillow did not help.

ridge-carter commented 1 year ago

Facing the same issue as well and updating pip and Pillow did not help. Running Google Colab on a Mac.

KaiquanMah commented 1 year ago

Dear friend, I use this code solve it

pip install --upgrade pip

pip install --upgrade Pillow

Linux, anaconda

Running these 2 lines solved the same 'TrueType font+' problem for another package - ydata-profiling

IshanRattan commented 1 year ago

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.

a-silliy-sheep commented 1 year ago

yeah, I'm very appreciate for your indication, which helps me a lot and gives me a direction actually. Along this way, I upgrade my Pillow, the course follows: firstly, I get a error when I directly use the code pip install --upgrade Pillow, as follows: raise ValueError("Only supported for TrueType fonts") ValueError: Only supported for TrueType fonts; which definitely make me crazy. finally I try other versions with the code pip3 install --upgrade Pillow==9.2.0 (you can use pip3 install --upgrade Pillow== to see what version you can use )that beyond mine but bellow the latest. many times later, I found my issue not existed anymore!

whoishrithikDS commented 1 year ago

pip install --upgrade Pillow

This might work and has worked for me while using ydata profling , etc

git-ankit-raj commented 1 year ago

Can anyone give a solution for VSC on this issue

DOMINION-JOHN1 commented 1 year ago

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'

B-din2018 commented 1 year ago

In my case installing the suggested lines worked (after restarting Jupyter Notebook)

emmanuelanene commented 1 year ago

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 pip

Shritej24c commented 1 year ago

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!

B-din2018 commented 1 year ago

My two cents in your case would be to try to execute the command in the cmd window (accessing it as an administrator instead of sudo). It might work (execute all that you did before, except maybe reinstalling wordcloud, but then I don't know). Good luck.

omar908 commented 1 year ago

Ran into the same issue, could not fix with upgrading pip or Pillow. Luckily I am using Conda, and created a new environment, then re-installed it now it works. My guess is a conflict on the environment I was already working on.

Below are the commands I used in order to get it working. (Note: some may not be needed for this to work):

conda create --name dataScience python=3.10

conda activate dataScience

conda install matplotlib

conda install wordcloud

B-din2018 commented 1 year ago

I followed the below instructions, and I got blocked after deinstalling datasSCience.

When trying to reinstall, executing conda activate dataScience I am told that I don’t have openSSL.

When downloading openSSL, you are prompted to make a donation of $10 but still get the error message that it is not installed.

After two unsuccessful attempts (20$) I am no longer willing to try this solution and exhort for solutions not involving financial transactions tied to them.

@.***

@.***

From: omar908 @.> Sent: Wednesday, August 16, 2023 3:30 PM To: amueller/word_cloud @.> Cc: bernardin moussa @.>; Comment @.> Subject: Re: [amueller/word_cloud] ValueError: Only supported for TrueTypefonts (Issue #729)

[Boxbe]https://www.boxbe.com/overviewomar908 @.**@.>) is not on your Guest Listhttps://www.boxbe.com/approved-list?tc_serial=59350397447&tc_rand=233313312&utm_source=stf&utm_medium=email&utm_campaign=ANNO_MWTP&utm_content=001&&key=MISam%2FTi%2Fm7iTvD1A7vNnY8GjEyTYbK%2BFoFvB%2BeVUPg%3D&token=x7N9OhXzynwCs6dPVaRUFzNwUtsFFfPZzgeZSZF8%2BcQ1HuXZqKLtdevjVuG1Q%2BpU | Approve senderhttps://www.boxbe.com/anno?tc_serial=59350397447&tc_rand=233313312&utm_source=stf&utm_medium=email&utm_campaign=ANNO_MWTP&utm_content=001&&key=MISam%2FTi%2Fm7iTvD1A7vNnY8GjEyTYbK%2BFoFvB%2BeVUPg%3D&token=x7N9OhXzynwCs6dPVaRUFzNwUtsFFfPZzgeZSZF8%2BcQ1HuXZqKLtdevjVuG1Q%2BpU | Approve domainhttps://www.boxbe.com/anno?tc_serial=59350397447&tc_rand=233313312&utm_source=stf&utm_medium=email&utm_campaign=ANNO_MWTP&utm_content=001&&dom&key=MISam%2FTi%2Fm7iTvD1A7vNnY8GjEyTYbK%2BFoFvB%2BeVUPg%3D&token=x7N9OhXzynwCs6dPVaRUFzNwUtsFFfPZzgeZSZF8%2BcQ1HuXZqKLtdevjVuG1Q%2BpU

Ran into the same issue, could not fix with upgrading pip or Pillow. Luckily I am using Conda, and created a new environment, then re-installed it now it works. My guess is a conflict on the environment I was already working on.

Below are the commands I used in order to get it working. (Note: some may not be needed for this to work):

conda create --name dataScience python=3.10

conda activate dataScience

conda install matplotlib

conda install wordcloud

— Reply to this email directly, view it on GitHubhttps://github.com/amueller/word_cloud/issues/729#issuecomment-1681160970, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AJDFDZEK2UI6E2HPNMVJKZDXVUNRVANCNFSM6AAAAAAYJRUCB4. You are receiving this because you commented.Message ID: @.**@.>>

B-din2018 commented 1 year ago

I strongly discourage this avenue. I tried it and after uninstalling dataScience and trying to reinstall it again, I got an error message telling me that I needed openSSL. When downloading openSSL from the net, the last step asks you to make a donation in order to be able to finish the setup. Which I did (twice) and it is still not working. image

B-din2018 commented 1 year ago

image

omar908 commented 1 year ago

@B-din2018 openSSL is free and should not be requiring any sort of payment. I am not sure where you are obtaining the installer from, but I suggest installing openSSL through conda if you are having issues installing it manually.

conda install -c anaconda openssl

https://anaconda.org/anaconda/openssl

B-din2018 commented 1 year ago

I used the command inside Jupyter this time and then tried to activate dataScience using the console again. No rejection, so I would like to think it worked image

omar908 commented 1 year ago

@B-din2018 I think you might have a misunderstanding on what the command conda activate dataScience actual does.

On the latest screenshot you can see in paranthesis to the left showing (dataScience) this means you already have activated the dataScience environment.

Switching environment does not create the issue you are facing, because it is just switching context within your local files.

The error you are getting with OpenSSL is when you try to install packages with conda. This still looks to be the case based upon your screenshot.

I recommend verifying if you have OpenSSL installed somewhere in your PC, and it could be that you just need to add it to your System Environments so the command line can utilize it.

Or you may need to install it manually again, but please remember OpenSSL is Free and should not require a payment. If you see it requesting donations, those might be optional and can be unchecked. IF it does not let you continue without donation/payment you might be using an incorrect installer, and I suggest stopping then and there and looking for a more legitimate one.

B-din2018 commented 1 year ago

@@.***> Would you be open to a joint session online? I am at 85% completion of my course and must absolutely jump over these last three hurdles:

Create (testing) classes from my samples | Get my confusion Matrix | Get my Tensorflow back working ?

I would be grateful if it is a possibility, if not I will also fully understand.

From: omar908 @.> Sent: Wednesday, August 23, 2023 3:39 PM To: amueller/word_cloud @.> Cc: Bernardin Moussa @.>; Mention @.> Subject: Re: [amueller/word_cloud] ValueError: Only supported for TrueType fonts (Issue #729)

@B-din2018https://github.com/B-din2018 I think you might have a misunderstanding on what the command conda activate dataScience actual does.

On the latest screenshot you can see in paranthesis to the left showing (dataScience) this means you already have activated the dataScience environment.

Switching environment does not create the issue you are facing, because it is just switching context within your local files.

The error you are getting with OpenSSL is when you try to install packages with conda. This still looks to be the case based upon your screenshot.

I recommend verifying if you have OpenSSL installed somewhere in your PC, and it could be that you just need to add it to your System Environments so the command line can utilize it.

Or you may need to install it manually again, but please remember OpenSSL is Free and should not require a payment. If you see it requesting donations, those might be optional and should be able to be unchecked. IF it does not let you continue without donation/payment you might be using an incorrect installer, and I suggest stopping then and there and looking for a more legitimate one.

- Reply to this email directly, view it on GitHubhttps://github.com/amueller/word_cloud/issues/729#issuecomment-1690532874, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AJDFDZFRXW7KTD2RYN7X7QDXWZL4DANCNFSM6AAAAAAYJRUCB4. You are receiving this because you were mentioned.Message ID: @.**@.>>

osman-haider commented 1 year ago

i am facing same issue

omar908 commented 1 year ago

@B-din2018 I might have some time during this week, during the day to try a few things quickly. But I suggest you try a few things beforehand so we know what has already been tried.

@@.> Would you be open to a joint session online? I am at 85% completion of my course and must absolutely jump over these last three hurdles: Create (testing) classes from my samples | Get my confusion Matrix | Get my Tensorflow back working ? I would be grateful if it is a possibility, if not I will also fully understand. From: omar908 @.> Sent: Wednesday, August 23, 2023 3:39 PM To: amueller/word_cloud @.> Cc: Bernardin Moussa @.>; Mention @.> Subject: Re: [amueller/word_cloud] ValueError: Only supported for TrueType fonts (Issue #729) @B-din2018https://github.com/B-din2018 I think you might have a misunderstanding on what the command conda activate dataScience actual does. On the latest screenshot you can see in paranthesis to the left showing (dataScience) this means you already have activated the dataScience environment. Switching environment does not create the issue you are facing, because it is just switching context within your local files. The error you are getting with OpenSSL is when you try to install packages with conda. This still looks to be the case based upon your screenshot. I recommend verifying if you have OpenSSL installed somewhere in your PC, and it could be that you just need to add it to your System Environments so the command line can utilize it. Or you may need to install it manually again, but please remember OpenSSL is Free and should not require a payment. If you see it requesting donations, those might be optional and should be able to be unchecked. IF it does not let you continue without donation/payment you might be using an incorrect installer, and I suggest stopping then and there and looking for a more legitimate one. - Reply to this email directly, view it on GitHub<#729 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AJDFDZFRXW7KTD2RYN7X7QDXWZL4DANCNFSM6AAAAAAYJRUCB4. You are receiving this because you were mentioned.Message ID: @*.**@*.***>>

BhuvanJoshi007 commented 1 year ago

Those who are facing issue in pip install --upgrade Pillow, use the command pip install --upgrade Pillow --user. This will install Pillow in your user's Python environment without requiring administrator privileges.

chesun commented 1 year ago

I am facing the same error on Red Hat Enterprise 7.9, Python 3.6. Upgrading pip and pillow did not work

SunbeltBrendan commented 1 year ago

I was getting the same ValueError: Only supported for TrueType fonts. (I was using a Juypter Notebook on my Windows laptop and using wordcloud with matplotlib.). I learned Matplotlib has a script called font_manager in which for Windows, it looks for fonts in 2 places:

I opened run and did %AppData% and drilled to the Roaming font directory and I found the AppData/Roaming/Microsoft/Windows/Fonts directory had no font files in it. I just copied the arial.ttf font via cmd to the roaming font directory and it seems to have solved my error.

Not sure what caused the font_manager to look under roaming but it ended up being a quick and easy fix.

Huangl19 commented 11 months ago

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!

it work for me