문제들
file load - FileNotFoundError: [Errno 2] No such file or directory:
tobedefined
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')