質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

2650閲覧

【その2】PythonでのWordCloudについて質問です

nyumonsya

総合スコア34

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2019/01/08 09:25

編集2019/01/08 10:02

Pythonを使用してWordCloud(テキストマイニング)を行いたいのですが、以下のコードを実行すると下段のエラーメッセージが表示され、止まってしまいます。
どうすれば動作するのでしょうか・・・何か足りないソフトがあるのでしょうか・・??
もし分かる方がいらっしゃったら、ご教示を頂きたいです。
よろしくお願いします。
※【その②】としているのは、私から類似タイトル(その①)で別内容の質問をしているため
※「text」の中身は仮の内容です

#!/usr/bin/env python import os print(os.getcwd()) # coding: utf-8 from wordcloud import WordCloud text = "Chief Justice Roberts, President Carter, President Clinton, President \ Bush, President Obama, fellow Americans, and people of the world: \ thank you. We, the citizens of America, are now joined in a great \ national effort to rebuild our country and to restore its promise for \ all of our people." wordcloud = WordCloud(background_color="white", font_path="/usr/share/fonts/truetype/takao-gothic/TakaoPGothic.ttf", width=800,height=600).generate(text) wordcloud.to_file("./wordcloud_sample.png")

◆ ◆ ◆ 以下、エラーメッセージ ◆ ◆ ◆

C:\python Traceback (most recent call last): File "C:/python/11b_wordcloud.py", line 16, in <module> width=800,height=600).generate(text) File "C:/python\wordcloud\wordcloud.py", line 605, in generate return self.generate_from_text(text) File "C:/python\wordcloud\wordcloud.py", line 587, in generate_from_text self.generate_from_frequencies(words) File "C:/python\wordcloud\wordcloud.py", line 426, in generate_from_frequencies max_font_size=self.height) File "C:/python\wordcloud\wordcloud.py", line 473, in generate_from_frequencies font = ImageFont.truetype(self.font_path, font_size) File "C:\Python37\lib\site-packages\PIL\ImageFont.py", line 280, in truetype return FreeTypeFont(font, size, index, encoding, layout_engine) File "C:\Python37\lib\site-packages\PIL\ImageFont.py", line 145, in __init__ layout_engine=layout_engine) OSError: cannot open resource >>>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

1つ前の質問欄のコメントに書いた内容ですが、
指定したフォントファイルがその場所にないのではないでしょうか?

font_path="/System/Library/Fonts/ヒラギノ明朝 ProN W3.otf"

Ascii 文字であれば、デフォルトのフォントでもうまくいくと思うので、引数自体消して試されてはどうですか?

python

1from wordcloud import WordCloud 2text = "Chief Justice Roberts, President Carter, President Clinton, President \ 3 Bush, President Obama, fellow Americans, and people of the world: \ 4 thank you. We, the citizens of America, are now joined in a great \ 5 national effort to rebuild our country and to restore its promise for \ 6 all of our people." 7 8def wordcloud(text): 9 wordcloud = WordCloud(background_color="white", 10 width=1024, height=674).generate(text) 11 wordcloud.to_file("test1.png") 12 13wordcloud(text)

投稿2019/01/08 09:45

tiitoi

総合スコア21956

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

nyumonsya

2019/01/08 10:24

tiitoiさん 「1つ前の質問」と同様、取り急ぎ引数自体を削除することで、生成出来ました! 誠にありがとうございます!!!!!!!!!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問