簡體   English   中英

IOError: 無法打開資源

[英]IOError: cannot open resource

我在 ipython notebook 上有一個代碼,我試圖在其中制作 wordcloud,但出現錯誤。 從我所看到的,錯誤與其他東西有關,而不是我的代碼(帶有字體的東西?)

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

我不太確定如何解釋這一點。 似乎我正在使用的一個類需要一些字體,而一些字體文件會發生一些事情。 任何見解將不勝感激

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

您需要在 wordcloud 對象中指定 font_path 。 的作者 Amueller 在他的最新版本中改變了很多東西。 我根據這些變化更新了我的項目,你可以在這里查看

在 Mac OS X 上,我收到錯誤消息:

IOError: cannot open resource

我更改了文件“wordcloud.py”中的 FONT_PATH

FONT_PATH = os.environ.get("FONT_PATH", "/Library/Fonts/Times New Roman.ttf")

錯誤消失了。

在 Mac OS X 上,我收到錯誤消息:

IOError: cannot open resource

我更改了文件“xxx.py”中的 FONT_PATH

 wc = WordCloud(
    max_words=100,
    width=2000,
    height=1200,
    font_path = 'Hiragino Sans GB.ttc'
)

它可以正確!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM