Home > Net >  FileNotFoundError: [Errno 2] No such file or directory, After copying pathname
FileNotFoundError: [Errno 2] No such file or directory, After copying pathname

Time:12-12

x_train = []
for i in range(1, 4): 
    base_dir = f'/Users/name/Desktop/cancer_data/stage_1_png' #pathname that I copy-pasted
    files = os.listdir(base_dir)
    for file in tqdm(files):
        img = imread(base_dir file)
        x_train.append(img)
x_train = np.array(x_train)
x_train.shape

I copy-pasted the pathname from the folder I want to extract images from, This same exact code was working before, but now I get the error message:

FileNotFoundError: [Errno 2] No such file or directory: '/Users/name/Desktop/cancer_data/stage_1_png'

I held down the Option key whilst in the folder, and clicked "copyPathname" (on mac). So it cannot possibly be a non-existent path/folder.

CodePudding user response:

check the filename again. I think it should be stage_1.png instead of stage_1_png

CodePudding user response:

It is a relative path. I prefer to use r"".
shift right click on the image file. You will find a copy path option and use that instead of path.

  • Related