TransWikia.com

"FileNotFoundError: [Errno 2] No such file or directory:" despite using full path

Stack Overflow Asked by Chloe Wong on January 5, 2022

Just wondering if someone might be able to point me in the right direction as I’m at complete loss of what’s happening (I’m a beginner so sorry if this is blaringly obvious!).

I’m writing some code to create a photomosaic. It requires resizing photos from a database and then concating images together to create a bigger picture.

The relevant code is as follows:

def resize(self):
        path = "C:/Users/chloe/Desktop/Python_Stuffs/Robert_Heaton/landscape_images"
        dirs = os.listdir(path)
        new_path = Path(path, 'resized_pics')
        new_path.mkdir(parents=True, exist_ok=True)
        #etc.
        
 def concat_rows(self):
        path = "C:/Users/chloe/Desktop/Python_Stuffs/Robert_Heaton"
        new_path_concat = Path(path, 'photomosaic_images_' + im_name)
        new_path_concat.mkdir(parents=True, exist_ok=True)
        counter = 0
        for row in self.match_pixel_img:
            im1_path = os.path.join(self.new_path,row.pop(0))
            os.chdir(self.new_path)
            im1 = Image.open(im1_path)
            #etc.
 

In the function resize I create a new directory with the new resized pictures in, and then in concat_rows I take the resized images from the new directory and concat them. However, I’m getting this error:

    File "C:UserschloeDesktopPython_StuffsRobert_Heatonphotomosaic.py", line 95, in concat_rows
    im1 = Image.open(im1_path)

    File "C:Userschloeanaconda3libsite-packagesPILImage.py", line 2878, in open
    fp = builtins.open(filename, "rb")

    FileNotFoundError: [Errno 2] No such file or directory: 
    'C:\Users\chloe\Desktop\Python_Stuffs\Robert_Heaton\landscape_images\resized_pics\'

even though this is the directory I created in resize and I can SEE the directory in my files at that exact location. I’m using the fullpath so I’m really not sure what is wrong. Furthermore, when I run the code a second time it works fine so maybe it’s something to do with the way Python reads lines?

If anyone could shed some light I’d be really grateful!

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP