简体   繁体   English

python:FileNotFoundError:[Errno 2]没有这样的文件或目录

[英]python: FileNotFoundError: [Errno 2] No such file or directory

I'm using google collab to learn python and machine learning. 我正在使用google collab来学习python和机器学习。 I'm trying to read the image files from /content/Images/ folder but for some reason, it is giving error - 我正在尝试从/ content / Images /文件夹中读取图像文件,但是由于某种原因,它给出了错误-

FileNotFoundError: [Errno 2] No such file or directory: '/content/Images/CM148.jpg' FileNotFoundError:[错误2]没有这样的文件或目录:'/content/Images/CM148.jpg'

. Here is my code: 这是我的代码:

 from PIL import Image
 path='/content/Images/'
 def load_images(abs_path):
    for image in train_images: #jpg
        print(abs_path+image)
        xpath = os.path.join(path,image)
        im=Image.open(xpath)
        np.append(image_list,im)
 load_images(path) 

I've gone through the questions here at stack overflow with similar problems. 我在堆栈溢出中遇到了类似的问题。 But specifying the absolute path seems to fix their errors. 但是指定绝对路径似乎可以解决他们的错误。

I'm sure that the images are present in the folder and I think I'm specifying the absolute path. 我确定文件夹中存在图像,并且我想指定的是绝对路径。 When I run this code, it gives me a little thumbnail as a preview: 当我运行此代码时,它为我提供了一些缩略图作为预览:

from IPython.display import Image
Image('/content/Images/CM148.jpg')

Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks 谢谢

当您可能应该输入绝对值时,您正在通过相对路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 3-FileNotFoundError:[Errno 2]没有这样的文件或目录 - Python 3 - FileNotFoundError: [Errno 2] No such file or directory Python FileNotFoundError:[错误2]没有这样的文件或目录 - Python FileNotFoundError: [Errno 2] No such file or directory Python FileNotFoundError: [Errno 2] 没有这样的文件或目录: - Python FileNotFoundError: [Errno 2] No such file or directory: Python 3.5:FileNotFoundError:[Errno 2]没有这样的文件或目录 - Python 3.5: FileNotFoundError: [Errno 2] No such file or directory Python 错误 FileNotFoundError: [Errno 2] 没有这样的文件或目录 - Python Error FileNotFoundError: [Errno 2] No such file or directory 我得到了 Python: FileNotFoundError: [Errno 2] No such file or directory - i got Python: FileNotFoundError: [Errno 2] No such file or directory Python FileNotFoundError: [Errno 2] No such file or directory: Synology 上的“ffprobe” - Python FileNotFoundError: [Errno 2] No such file or directory: 'ffprobe' on Synology Python/Docker: FileNotFoundError: [Errno 2] 没有这样的文件或目录: - Python/Docker : FileNotFoundError: [Errno 2] No such file or directory: Python 3:如何修复FileNotFoundError:[Errno 2]没有这样的文件或目录 - Python 3: How to fix FileNotFoundError: [Errno 2] No such file or directory Heroku Python FileNotFoundError:[Errno 2] 没有这样的文件或目录 - Heroku Python FileNotFoundError: [Errno 2] No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM