在Jupyter笔记本上运行程序时,找不到os.listdir(path)路径

2024-09-28 22:33:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我在windows 10上的jupyter笔记本中工作,试图运行以下程序:

ad = 'C:\\Users\\S m\\mbdataset\\trainmbds'
CAT = ['0 to 10','10 to 20','20 to 30','30 to 40','40 to 50']
for cat in CAT:
 path = os.path.join(ad, cat)
  for img in os.listdir(path):
    img_array = cv2.imread(os.path.join(path,img))
     plt.imshow(img_array)
      plt.show
      break
    break 

在上面的返回中,我得到以下错误:

FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\S m\\mbdataset\\trainmbds\\0 to 10'

虽然0 to 10的地址也是C:\Users\S m\mbdataset\trainmbds\0 to 10,但我尝试用各种斜杠(/,\和\\)来写地址,它显示了相同的错误。 我遇到这个问题是因为我的文件路径地址中有太多的空格


Tags: topathinimgforos地址array