teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

追記

2020/07/07 08:13

投稿

8524ba23
8524ba23

スコア38352

answer CHANGED
@@ -1,2 +1,13 @@
1
1
  原因は`FileNotFoundError: [Errno 2] No such file or directory: 'hasira.png'`です。
2
- カレントディレクトリに画像ファイルを配置してください。一般的には`kime4.py`と同じ場所でよいです。
2
+ カレントディレクトリに画像ファイルを配置してください。一般的には`kime4.py`と同じ場所でよいです。
3
+
4
+ 以下のようなコードでファイルの存在確認ができます。
5
+ ```Python
6
+ import os
7
+
8
+ img_path = 'hasira.png'
9
+ print( img_path, os.path.exists(img_path))
10
+ img_path = os.path.join( os.getcwd(), 'hasira.png') # getcwdはカレントディレクトリパスを返す
11
+ print(img_path, os.path.exists( img_path))
12
+
13
+ ```