各位友友们可以帮俺看看吗?这是啥问题
以下我写的代码
#导入os模块
import os
#导入image包
import shutil
from PIL import Image
path = "D:\python\gaizi"
save = "D:/python/abc_666"
file_list = os.listdir(path)
for file in file_list:
imgPath = os.path.join(path, file)
img = Image.open(imgPath)
imgSize = img.size
print(imgSize, imgPath)
minSize = min(imgSize)
if minSize >= 320:
images_min = os.path.join(save, file) + ".jpg"
shutil.copy(imgPath, images_min)
img.close()
print(minSize)
if name == "main":
if not os.path.exists(save):
os.makedirs(save)
print(file)
最后报错为:
C:\ProgramData\Anaconda3\python.exe D:/code/Test/test1/imgsize.py
Traceback (most recent call last):
File "D:/code/Test/test1/imgsize.py", line 13, in
img = Image.open("imgPath")
File "C:\ProgramData\Anaconda3\lib\site-packages\PIL\Image.py", line 3092, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'imgPath'
你应该学会看报错信息:FileNotFoundError: [Errno 2] No such file or directory: 'imgPath'
很明显是没有 imgPath
这个文件或路径。
你在前面也没定义 imgPath
。
如果对你有帮助,还请帮忙点个采纳,谢谢!