【发布时间】:2022-01-23 22:30:54
【问题描述】:
我正在尝试从此目录打开图像,但无法打开。它给了我以下错误:
FileNotFoundError Traceback (most recent call last)
<ipython-input-27-1840203b5591> in <module>
4
5 file = path+'\\'+a
----> 6 Image.open(file).show()
7 #files=os.listdir(path)
8 #emoji=random.choice(files)
/usr/lib/python3/dist-packages/PIL/Image.py in open(fp, mode)
2807
2808 if filename:
-> 2809 fp = builtins.open(filename, "rb")
2810 exclusive_fp = True
2811
FileNotFoundError: [Errno 2] No such file or directory: '/home/laura/Desktop/TheLab/nft/Emojis\\031-happy-2.png'
这是我的代码:
import os
from PIL import Image
import random
import numpy as np
path = r"/home/laa/Desktop/TheLab/nft/Emojis"
a=random.choice(os.listdir(path))
print(a)
file = path+'\\'+a
Image.open(file).show()
我不知道每次打印 a 时会发生什么,它会显示带有 .png 扩展名的图像名称,但稍后不会显示。
【问题讨论】:
-
它告诉你提供的路径不正确,尝试提供完整路径
标签: python path operating-system python-imaging-library filepath