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

font issue with pygame #6

Open
rblakemesser opened this issue Mar 30, 2012 · 11 comments
Open

font issue with pygame #6

rblakemesser opened this issue Mar 30, 2012 · 11 comments

Comments

@rblakemesser
Copy link

This might not be a pytagcloud issue per se... but here goes.

I'm getting a IO error related to the font filenames. I assume it's a pygame problem:

Traceback (most recent call last):
File "/home/blake/Dropbox/2012.03_WorkCode/tagcloud.py", line 41, in
File "/usr/local/lib/python2.7/dist-packages/pytagcloud/init.py", line 344, in create_tag_image
File "/usr/local/lib/python2.7/dist-packages/pytagcloud/init.py", line 275, in _draw_cloud
File "/usr/local/lib/python2.7/dist-packages/pytagcloud/init.py", line 62, in init
IOError: unable to read font filename

When I run the example code off your site, it runs though without a problem. I just can't figure out for the life of me why my code, which uses the same font as the example, won't run.

Here's my code......

import csv
from pytagcloud import create_tag_image, make_tags
from pytagcloud.lang.counter import get_tag_counts

input_csv = csv.reader(open('sql_output.csv','rb'),delimiter="~")

....[some stuff here that creates a list of word frequency tuples from my csv data]

word_frequencies = []
for n,irecord in enumerate(sorted(word_freqs.items(), key=lambda item: item[1])):
word_frequencies.append(tuple([irecord[0],irecord[1]]))

tags = make_tags(word_frequencies, maxsize=120)

create_tag_image(tags, 'cloud_large2.png', size=(900, 600), fontname='Lobster')

@rblakemesser
Copy link
Author

More investigation shows that the error is only thrown if the size of the word_frequencies list is too large. For example, when I limit it to 300 words, then the font error is not thrown. I wonder if somewhere in the middle of my list there are special characters that are not available in the packaged fonts...?

@alourenco
Copy link

I had a similar error when adapting the example to my own problem:

In [7]: Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in call
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 498, in callit
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 263, in idle_draw
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 248, in draw
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py", line 394, in draw
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 798, in draw
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 1946, in draw
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 1017, in draw
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 234, in draw
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
File "/usr/lib/pymodules/python2.7/matplotlib/text.py", line 526, in draw
File "/usr/lib/pymodules/python2.7/matplotlib/text.py", line 300, in _get_layout
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py", line 180, in get_text_width_height_descent
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py", line 221, in _get_agg_font
RuntimeError: Could not open facefile /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf; Cannot_Open_Resource

Here is my code:
print "ploting tag-clouds..."
size=(900, 600)
for i in range(k):
print "tag:",i
t=[(vocabNew2[d],vocabWeight[i,d]) for d in range(len(vocabNew2))]
t=(tuple(t))
tags = make_tags(t, maxsize=120)
create_tag_image(tags, fileName + 'cloud_cluster-'+str(i)+'.png', size=size, fontname='Nobile')

I will try to limit the number of tokens...

@justis justis mentioned this issue Jun 21, 2012
@aeby
Copy link
Member

aeby commented Jun 28, 2012

Can you check if https://github.com/atizo/PyTagCloud/commits/master8361a4d1f3a1a22a87b23f0787242d0ac6181618 fixes your problem? Thanks!

@alourenco
Copy link

Thank you aeby, I will check it!

@ila987
Copy link

ila987 commented Dec 20, 2012

Hello everybody!

I have the get the same error when I give as input a text sequence too big:

IOError: unable to read font file '/pytagcloud-0.3.5/pytagcloud/fonts/nobile.ttf'

I modified init.py with b19d236, but I still get the same error..

Any help is really appreciated!
Thanks

@arianpasquali
Copy link

Same error here. Still can't find a way to workaround this issue.

create_tag_image(tags, str(cluster_id) + '_wordcloud.png', size=(900, 700))

Traceback (most recent call last):
File "text_clustering.py", line 292, in
File "text_clustering.py", line 257, in main
File "text_clustering.py", line 226, in perform_clustering
File "text_clustering.py", line 59, in plot_wordclouds
File "/Library/Python/2.7/site-packages/pytagcloud/init.py", line 344, in create_tag_image
File "/Library/Python/2.7/site-packages/pytagcloud/init.py", line 275, in _draw_cloud
File "/Library/Python/2.7/site-packages/pytagcloud/init.py", line 62, in init
IOError: unable to read font file '/Library/Python/2.7/site-packages/pytagcloud/fonts/DroidSans.ttf'

@ghost
Copy link

ghost commented Jul 5, 2013

Still getting this same error. Is there a solution anywhere?

@srirajan
Copy link

From what I gathered, this seems to be a problem with input data. I tested with normal words and was able to run it against 1000s of words but it does fail with that error for some data. Not sure what trips it though.

@fnielsen
Copy link

The problem seems to be too many open files. As create_tag_image is called again and again the number of font file references increases. In my Ubuntu system I can see the open files in /proc/PID/fd/ where PID is the process identifier for the python process. I believe it is around 1000 open files that I run into troubles. My ulimit -a tells me I "open file" "1024" which fits well with my observation. For small examples like in the README.rst the number of files only increases a little each time, but with a larger text the number of files in /proc/PID/fd increases quickly, e.g.:

from nltk.corpus import brown
tags = make_tags(get_tag_counts(" ".join(brown.words()[:1000])))
create_tag_image(tags, 'cloud_large.png', size=(900, 600), fontname='Lobster')

The number of files fits well with the size of the FONTS variable. However, del FONTS, pygame.quit(), pygame.font.quit(), del pygame or del pytagcloud do not help.

@fnielsen
Copy link

@smagnan
Copy link

smagnan commented Mar 10, 2016

I had this error appearing randomly in a cloud generation loop (independent of which cloud was generated it seems)

building word cloud for user BBC News (World)
word cloud built
building word cloud for user Human Rights Watch
word cloud built
building word cloud for user InThePanda
Traceback (most recent call last):
  File "main.py", line 217, in <module>
  File "main.py", line 181, in analyse_twitter_data
  File "main.py", line 133, in atd_word_cloud
  File "main.py", line 121, in build_cloud
  File "/home/smagnan/Documents/365Talents/Twitter/user.py", line 41, in word_cloud
  File "/usr/local/lib/python2.7/dist-packages/pytagcloud/__init__.py", line 344, in create_tag_image
  File "/usr/local/lib/python2.7/dist-packages/pytagcloud/__init__.py", line 275, in _draw_cloud
  File "/usr/local/lib/python2.7/dist-packages/pytagcloud/__init__.py", line 62, in __init__
IOError: unable to read font filename

After investigation it also seemed to me it was too many open files as stated by @fnielsen
The evil workaround solved this issue (see previous post), but sometimes causes python to crash when exiting my program ...
Anyway, this workaround seems to be working until the issue is solved

infocat-kr pushed a commit to infocat-kr/PyTagCloud that referenced this issue Feb 6, 2017
…or repeated reloads of the same font. This fixed an issue I had with it crashing when repeatedly rendering the same cloud in a loop. This may also fix atizo/PyTagCloud#6
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

8 participants