Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Only supported for TrueType fonts #729

Open
talha2k opened this issue May 21, 2023 · 33 comments
Open

ValueError: Only supported for TrueType fonts #729

talha2k opened this issue May 21, 2023 · 33 comments

Comments

@talha2k
Copy link

talha2k commented May 21, 2023

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
Copy link
Author

talha2k commented May 21, 2023

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
Copy link

Dear friend, I use this code solve it

pip install --upgrade pip

pip install --upgrade Pillow

Linux, anaconda

@JainShubham23
Copy link

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

@danielqingz
Copy link

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

@opgeROBt
Copy link

opgeROBt commented May 29, 2023

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
Copy link

pip install --upgrade Pillow

Did the trick for me!

@dbetm
Copy link

dbetm commented Jun 15, 2023

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

@a-ibrahimi
Copy link

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

@ridge-carter
Copy link

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

@KaiquanMah
Copy link

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
Copy link

IshanRattan commented Jul 4, 2023

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
Copy link

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
Copy link

pip install --upgrade Pillow

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

@git-ankit-raj
Copy link

Can anyone give a solution for VSC on this issue

@DOMINION-JOHN1
Copy link

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
Copy link

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

@emmanuelanene
Copy link

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
Copy link

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
Copy link

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
Copy link

omar908 commented Aug 16, 2023

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
Copy link

B-din2018 commented Aug 21, 2023 via email

@B-din2018
Copy link

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
Copy link

image

@omar908
Copy link

omar908 commented Aug 21, 2023

@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
Copy link

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
Copy link

omar908 commented Aug 23, 2023

@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
Copy link

B-din2018 commented Aug 23, 2023 via email

@osman-haider
Copy link

i am facing same issue

@omar908
Copy link

omar908 commented Aug 28, 2023

@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
Copy link

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
Copy link

chesun commented Sep 27, 2023

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

@SunbeltBrendan
Copy link

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:

  •  AppData/Local/Microsoft/Windows/Fonts')
    
  •   AppData/Roaming/Microsoft/Windows/Fonts
    

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests