IOError:无法打开资源 [英] IOError: cannot open resource

查看:676
本文介绍了IOError:无法打开资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ipython笔记本上有一个代码,我试图做一个wordcloud,但我得到一个错误。从我所能看到的,这个错误是与别的东西有关的,而不是我的代码(有字体的东西?)

  --- -------------------------------------------------- ---------------------- 
IOError Traceback(最近一次调用最后一次)
< ipython-input-71-795b92e06f22> in< module>()
4#print x [0],x [1]
5
----> 6 genWordCloud(list_of_tuples)

< ipython-input-70-55c34fb2c915> in genWordCloud(filename)
15 count = filename
16 #words = myWC.fit_words(count,width = 500,height = 500)
---> (word,pngPath + os.path.splitext(filename)[0] +'.png',width = 500,height = 500,scale = 1 )
19 return {}生成的云格式(文件名)

/usr/local/lib/python2.7/dist-packages/wordcloud/wordcloud.pyc in fit_words(自我,单词)
177而真:
178#尝试找到一个位置
- > 179 font = ImageFont.truetype(self.font_path,font_size)
180#转置字体可选
181 if random_state.random()< self.prefer_horizo​​ntal:

/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.pyc truetype(字体,大小,索引,编码,文件名)
238
239试试:
- > 240返回FreeTypeFont(字体,大小,索引,编码)
除了IOError:
242如果sys.platform ==win32:

/ usr / local / lib / python2.7 / dist-packages / PIL / ImageFont.pyc in __init __(self,font,size,index,encoding,file)
135 $ b $ 136 ifPath(font):
- > 137 self.font = core.getfont(font,size,index,encoding)
138 else:
139 self.font_bytes = font.read()

IOError:无法打开资源

我不太确定如何解释这个。看起来像我正在使用的类需要一些字体,并且某些字体文件发生了一些事情。任何见识将不胜感激

我以此为基础: http://99projects.co/reports/p05-word-frequency/

解决方案

你需要在你的wordcloud对象中指定一个font_path。他的最新版本图书馆的作者Amueller改变了很多东西。我根据这些更改更新了我的项目,您可以检查它在这里


I have a code on ipython notebook where I am attempting to make a wordcloud, but I get an error. From what I could see, the error is related to something else and not my code (something with fonts?)

---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-71-795b92e06f22> in <module>()
  4 #    print x[0], x[1]
  5 
----> 6 genWordCloud(list_of_tuples)

<ipython-input-70-55c34fb2c915> in genWordCloud(filename)
 15     count = filename
 16     #words = myWC.fit_words(count, width=500, height=500)
---> 17     words = myWC.fit_words(count)
 18     myWC.draw(words, pngPath + os.path.splitext(filename)[0] + '.png', width=500, height=500, scale=1)
 19     return 'Cloud generated for {}'.format(filename)

/usr/local/lib/python2.7/dist-packages/wordcloud/wordcloud.pyc in fit_words(self, words)
177             while True:
178                 # try to find a position
--> 179                 font = ImageFont.truetype(self.font_path, font_size)
180                 # transpose font optionally
181                 if random_state.random() < self.prefer_horizontal:

/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.pyc in truetype(font, size, index, encoding, filename)
238 
239     try:
--> 240         return FreeTypeFont(font, size, index, encoding)
241     except IOError:
242         if sys.platform == "win32":

/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.pyc in __init__(self, font, size, index, encoding, file)
135 
136         if isPath(font):
--> 137             self.font = core.getfont(font, size, index, encoding)
138         else:
139             self.font_bytes = font.read()

IOError: cannot open resource

I'm not so sure as to how to interpret this. Seems like a class I'm using needs some fonts, and something happens with some font files. Any insight will be appreciated

I am using this as a base: http://99projects.co/reports/p05-word-frequency/

解决方案

You'll need to specify a font_path in your wordcloud object. Amueller, the author of the library changed a lot of things in his latest version. I updated my project according to these changes, you can check it here

这篇关于IOError:无法打开资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆