Python 没有这样的文件或目录:';builtup/build0.jpg';
在我准备的satellite images文件夹中打印前9张图像时,键入文件夹路径“Building”,它会显示:Python 没有这样的文件或目录:';builtup/build0.jpg';,python,Python,在我准备的satellite images文件夹中打印前9张图像时,键入文件夹路径“Building”,它会显示: FileNotFoundError: [Errno 2] No such file or directory 我会做一些像 import os filename = os.path.join( os.path.dirname(os.path.abspath(__file__)), folder, 'build{}.jpg'.format(i) )
FileNotFoundError: [Errno 2] No such file or directory
我会做一些像
import os
filename = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
folder,
'build{}.jpg'.format(i)
)
使用图像的绝对路径
import os
absolute_path = os.path.join(os.getcwd(), 'builtup', 'build', str(i) + '.jpg');
您可以迭代给定文件夹中的所有文件并检查它们是否为.jpg/.jpg
from matplotlib import pyplot
from matplotlib.image import imread
import os
#also try with full path:
folder = '/builtup/'
i=0
for file in os.listdir(folder):
if file.endswith('.jpg') or file.endswith('.JPG'):
if i <= 8:
pyplot.subplot(330 + 1 + i)
image = imread(os.path.join(folder,file))
pyplot.imshow(image)
i=i+1
pyplot.show()
从matplotlib导入pyplot
从matplotlib.image导入imread
导入操作系统
#还可以尝试使用完整路径:
文件夹='/builtup/'
i=0
对于os.listdir(文件夹)中的文件:
如果file.endswith('.jpg')或file.endswith('.jpg'):
如果我把代码贴在这里,而不是图片你不明白什么?该文件不存在我已通过将图像名称从[build(0.jpg]重命名为[build.0.jpg]修复了此错误