file load - FileNotFoundError: [Errno 2] No such file or directory:
2020. 9. 8. 21:09ㆍ문제들
python에서 file load 시, 분명 경로에 잘 접근했는데 file not found error가 뜬다
Traceback (most recent call last):
File "e:\online_lecture\ml\ai\sources\Day6\cnn\apply_filter_5.py", line 33, in <module>
img = imread('./dataset/lena_gray.png')
File "C:\Users\computer\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\image.py", line 1476, in imread
with img_open(fname) as image:
File "C:\Users\computer\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\ImageFile.py", line 105, in __init__
self.fp = open(fp, "rb")
FileNotFoundError: [Errno 2] No such file or directory: './dataset/lena_gray.png'
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command python e:\online_lecture\ml\ai\sources\Day6\cnn\apply_filter_5.py" terminated with exit code: 1.
이런 식으로 말이다.
이럴 때는
import os
# \\ -> / 로 변환한다. 윈도우 기준이다.
dir = os.path.dirname(os.path.realpath(__file__)).replace('\\', '/') + '/'
img = imread(dir + './dataset/lena_gray.png')
이렇게 절대 경로로 파일을 열어줘야 한다.
happy하다
'문제들' 카테고리의 다른 글
[JavaScript] forEach is not a function error (0) | 2021.03.26 |
---|---|
[JDBC] MySQL Error Code 1175 발생시 해결법 (0) | 2021.03.13 |
Permission denied (publickey).fatal: Could not read from remote repository. (0) | 2020.08.13 |
Error: Hostname/IP doesn't match certificate's altnames (0) | 2020.08.12 |
docker error during connect 시 해결법 (0) | 2020.07.18 |