为什么在尝试打开目录时会出现错误?

时间:2021-06-13 13:46:43

标签: python directory

所以基本上我想要做的是从我的目录中获取我的文件,遵循本教程: https://www.youtube.com/watch?v=j-3vuBynnOE,以及这个 kaggle 数据集:https://www.kaggle.com/rishianand/devanagari-character-set

但是好像出错了?


#loading in data from kaggle 
#from :https://www.youtube.com/watch?v=j-3vuBynnOE

#importing the libraries to see the actual images
import numpy as np 
import matplotlib.pyplot as plt 
import os
import cv2

#the kaggle download had three folders(consonants, vowels and numbers), looking at the vowels number

DATADIR=  "C:/Users/binju/Downloads/archive.zip/Images/Images"
CAT= ['character_1_ka', 'character_2_kha',  'character_3_ga',  'character_4_gha',  'character_5_kna']
#paths directory


for category in CAT:
    path= os.path.join(DATADIR, category)
    print("this is the path:", path)
    for img in os.listdir(path):
        print(img)
        #converting images into arrays
        img_array= cv2.imread(os.path.join(path, img), cv2.IMREAD_GRAYSCALE)
        plt.imshow(img_array, cmap="gray")
        plt.show()
        break
    break

和错误:

  File "c:\Users\binju\csgr12project.py", line 29, in <module>Images\character_1_ka                                                              _ka
    for img in os.listdir(path):
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:/Users/binju/Downloads/archive.zip/Images/Images/character_1_ka'                                            

但是当我在下载文件中找到我的实际文件并按下它时,显示的是:

C:\Users\binju\Downloads\archive.zip\Images\Images\character_01_ka

我更改了斜线,因为 \ 似乎不起作用但是 / 确实...但我不认为斜线是问题

2 个答案:

答案 0 :(得分:0)

您的 CAT 包含

CAT= ['character_1_ka', 'character_2_kha',  'character_3_ga',  'character_4_gha',  'character_5_kna']

调用文件时

CAT= ['character_01_ka', 'character_02_kha',  'character_03_ga',  'character_04_gha',  'character_05_kna']

答案 1 :(得分:0)

你可以试试这个 C:\\...\\...