Filenotfounderror: [Errno 2] No Such File or Directory ,Even I Have the Image in That Particular Folder

FileNotFoundError: [Errno 2] No such file or directory ,even I have the image in that particular folder

Your path is incorrect when you open the single image, it should be:

a = Image.open(path2 + '\\'+ imlist[0])

FileNotFoundError: [Errno 2] No such file or directory for pictures on Python 3.7

If the image file "v" is in the same folder as your python code, your code should load it. The error shows it is missing the file. I would recommend checking for file extensions (maybe file name is "v.jpg").

And if your file is not in the python folder and is in a different folder,
the easiest way is to include the full address to your image file:

image=Image.open("full_path_to_file/"+"v")

The same approach with better practice would be like this:

import os
image=Image.open(os.path.join("full_path_to_file", "v"))

You can also use the relational address to file. "../" will take you to one directory above your current directory. For example, if your file directory structure is:

  • directory

    • |
    • v.jpg
    • subdirectory

      • |
      • your_python_code.py

You can use:

image=Image.open("../v")

FileNotFoundError: [Errno 2] No such file or directory in Opencv face_recognition python

It says that there is no such directory as a.jpg in the "dataset" folder

No, that is not what the error means.

The code is looking for that file in the current directory, not in the dataset folder.

You did call os.listdir(r'/home/pi/Desktop/dataset/'), but that does not change the current directory.

Use the full pathname to open the file:

img=face_recognition.load_image_file("/home/pi/Desktop/dataset/a.jpg")


Related Topics



Leave a reply



Submit