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

OSError: cannot open resource #450

Open
diegoelages opened this issue Nov 8, 2018 · 4 comments
Open

OSError: cannot open resource #450

diegoelages opened this issue Nov 8, 2018 · 4 comments

Comments

@diegoelages
Copy link

diegoelages commented Nov 8, 2018

Description

Error: OSError: cannot open resource

Steps/Code to Reproduce

from PIL import Image
import numpy as np
from wordcloud import WordCloud

words = 'access guest guest apartment area area bathroom bed bed bed bed bed bedroom block coffee coffee coffee coffee entrance entry francisco free garden guest home house kettle kettle kitchen kitchen kitchen kitchen kitchen kitchenliving located microwave neighborhood new park parking place privacy private queen room san separate seperate shared space space space street suite time welcome'
scale = 12
mask = Image.open('c:/temp/images.png')
width, height = mask.size
mask = np.array(mask.resize((int(mask.size[0] / float(scale)), int(mask.size[1] / float(scale)))))
wordcloud = WordCloud(scale=scale, background_color='white', width=int(width/float(scale)), height=int(height/float(scale)), margin=2, font_path='msyh.ttc', mask=mask).generate(words)
wordcloud.to_file('c:/temp/out.png')

Expected Results

No erro :-)

Actual Results

PS D:\Diego\ProjetosPython\Aprendizado-master> python cloud2.py
Traceback (most recent call last):
File "cloud2.py", line 10, in
wordcloud = WordCloud(scale=scale, background_color='white', width=int(width/float(scale)), height=int(height/float(scale)), margin=2, font_path='msyh.ttc', mask=mask).generate(words)
File "D:\Usuários\dlsan\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wordcloud\wordcloud.py", line 605, in generate
return self.generate_from_text(text)
File "D:\Usuários\dlsan\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wordcloud\wordcloud.py", line 587, in generate_from_text
self.generate_from_frequencies(words)
File "D:\Usuários\dlsan\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wordcloud\wordcloud.py", line 426, in generate_from_frequencies
max_font_size=self.height)
File "D:\Usuários\dlsan\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wordcloud\wordcloud.py", line 473, in generate_from_frequencies
font = ImageFont.truetype(self.font_path, font_size)
File "D:\Usuários\dlsan\AppData\Local\Programs\Python\Python36-32\lib\site-packages\PIL\ImageFont.py", line 280, in truetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "D:\Usuários\dlsan\AppData\Local\Programs\Python\Python36-32\lib\site-packages\PIL\ImageFont.py", line 145, in init
layout_engine=layout_engine)
OSError: cannot open resource

Versions

Windows-7-6.1.7601-SP1
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)]
NumPy 1.15.3
matplotlib 3.0.1
wordcoud 1.5.0

@diegoelages
Copy link
Author

images

@amueller
Copy link
Owner

amueller commented Nov 8, 2018

looks like it can't open the font. Can you check if "D:\Usuários\dlsan\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wordcloud\DroidSansMono.ttf" exists?
Can you also check what wordcloud.font_path is?

And just in case I'm wrong, can you please also see what happens if you remove the last line?

@hugovk
Copy link

hugovk commented Nov 28, 2018

This looks like a bug in Pillow on Windows with paths containing non-ASCII characters, from the accented á in Usuários.

A workaround is to copy the font to a path that contains only ASCII characters.

See python-pillow/Pillow#3145.

@amueller
Copy link
Owner

@hugovk good catch!

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

3 participants