简体   繁体   English

在 python WindowsError: [错误 3] 系统找不到指定的路径:'F:/Dataset\\*.*'

[英]In python WindowsError: [Error 3] The system cannot find the path specified: 'F:/Dataset\\*.*'

for category in CATEGORIES:  # do dogs and cats
    path = os.path.join(DATADIR,category)  # create path to dogs and cats
    for img in os.listdir(path):  # iterate over each image per dogs and cats
        img_array = cv2.imread(os.path.join(path,img) ,cv2.IMREAD_GRAYSCALE)  # convert to array
        plt.imshow(img_array, cmap='gray')  # graph it
        plt.show()  # display!

error occurred:发生了错误:

WindowsErrorTraceback (most recent call last)
<ipython-input-4-be2d68025f07> in <module>()
      1 for category in CATEGORIES:  # do dogs and cats
      2     path = os.path.join(DATADIR,category)  # create path to dogs and cats
----> 3     for img in os.listdir(path):  # iterate over each image per dogs and cats
      4         img_array = cv2.imread(os.path.join(path,img) ,cv2.IMREAD_GRAYSCALE)  # convert to array
      5         plt.imshow(img_array, cmap='gray')  # graph it

WindowsError: [Error 3] The system cannot find the path specified: 'F:/Dataset\\Bening\\*.*'
WindowsError: [Error 3] The system cannot find the path specified: 'F:/Dataset\\Bening\\*.*'

The error literally says the path is wrong.该错误字面意思是路径错误。

Let's look more closely:让我们更仔细地看一下:

We have os.listdir(path) with an error caused by 'F:/Dataset\\Bening\\*.*'我们有一个由'F:/Dataset\\Bening\\*.*'引起的错误的os.listdir(path)

Firstly, paths in Python don't use wildcards .首先, Python 中的路径不使用通配符 . . It's an os.listdir , so you pass a directory in there.这是一个os.listdir ,所以你在那里传递一个目录。 If you want to use wildcards, try glob .如果您想使用通配符,请尝试glob

Secondly, you use wrong separator in your definition of DATADIR - os.path.join uses the system-specific one which is backslash in Windows (double backslash in print because it needs escaping), you use a normal, forward slash.其次,您在DATADIR的定义中使用了错误的分隔符 - os.path.join使用系统特定的分隔符,即 Windows 中的反斜杠(打印中的双反斜杠,因为它需要转义),您使用正常的正斜杠。 You can put the path with backslashes by putting r just before opening the string (it means the string is raw - backslashes are literal, not an escaping sequence) or by doubling the backslashes manually.您可以通过在打开字符串之前放置r来放置带有反斜杠的路径(这意味着字符串是原始的 - 反斜杠是文字,而不是 escaping 序列)或手动加倍反斜杠。 r'F:\Dataset' or 'F:\\Dataset r'F:\Dataset''F:\\Dataset

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows / Python错误WindowsError:[错误3]系统找不到指定的路径 - Windows/Python Error WindowsError: [Error 3] The system cannot find the path specified WindowsError:[错误3]系统找不到指定的路径? - WindowsError: [Error 3] The system cannot find the path specified? WindowsError:[错误3]系统找不到指定的路径 - WindowsError: [Error 3] The system cannot find the path specified Shuutil.copytree ----&gt; WindowsError: [错误 3] 系统找不到指定的路径: - Shutil.copytree ----> WindowsError: [Error 3] The system cannot find the path specified: WindowsError:[错误2]系统找不到指定的文件,无法在Python中解析 - WindowsError: [Error 2] The system cannot find the file specified, cannot resolve in Python WindowsError(3,&#39;系统找不到指定的路径&#39;) - WindowsError(3, 'The system cannot find the path specified') Python错误:WindowsError:[错误2]系统找不到指定的文件: - Python Error: WindowsError: [Error 2] The system cannot find the file specified: Python(Portable 2.5)子进程报告问题“ WindowsError:[Error 3]系统找不到指定的路径” - Python (Portable 2.5) subprocess report problem “WindowsError: [Error 3] The system cannot find the path specified” 在 Python 中重命名文件:WindowsError: [错误 2] 系统找不到指定的文件 - rename file in Python: WindowsError: [Error 2] The system cannot find the file specified Python - WindowsError: [错误 2] 系统找不到指定的文件 - Python - WindowsError: [Error 2] The system cannot find the file specified
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM