word_cloud: cannot open resource
I try to use it on Mac OS and there is a problem with PIL I think:
---------------------------------------------------------------------------
IOError Traceback (most recent call last)
<ipython-input-148-0d09cb35794e> in <module>()
2 elements = wordcloud.fit_words(freq_dist.items()[:200], width=500, height=500, font_path='/Users/paul/Library/Fonts/Verdana.ttf')
3 # Draw the positioned words to a PNG file.
----> 4 wordcloud.draw(elements, 'tagcloud-%s.png' % hashtag, width=500, height=500)
/Library/Python/2.7/site-packages/wordcloud/__init__.pyc in draw(elements, file_name, font_path, width, height, scale, color_func)
145 draw = ImageDraw.Draw(img)
146 for (word, count), font_size, position, orientation in elements:
--> 147 font = ImageFont.truetype(font_path, font_size * scale)
148 transposed_font = ImageFont.TransposedFont(font,
149 orientation=orientation)
/Library/Python/2.7/site-packages/PIL/ImageFont.pyc in truetype(filename, size, index, encoding)
216 and "armn" (Apple Roman). See the FreeType documentation
217 for more information.
--> 218 :return: A font object.
219 :exception IOError: If the file could not be read.
220 """
/Library/Python/2.7/site-packages/PIL/ImageFont.pyc in __init__(self, file, size, index, encoding)
132 else:
133 self.font_bytes = font.read()
--> 134 self.font = core.getfont("", size, index, encoding, self.font_bytes)
135
136 def getname(self):
IOError: cannot open resource
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 20 (10 by maintainers)
Commits related to this issue
- FONT_PATH env var is now respected Fixes #12. — committed to laserson/word_cloud by laserson 10 years ago
On my windows 7 machine, specifying font_path=‘C:\Windows\Fonts\msyh.ttf’ works well. I am generating word cloud for Chinese characters. FYI.