NotADirectoryError: [WinError 267] 目录名称无效:’C:\\masksdetection-master//Recog_Train/.DS_Store/’

原文标题NotADirectoryError: [WinError 267] The directory name is invalid: ‘C:\\masksdetection-master//Recog_Train/.DS_Store/’

代码

这是代码,当我运行它时,我得到了以下错误。有人可以帮我解决这个问题。

PS C:\masksdetection-master> python -u "c:\masksdetection-master\Face_recog.py"
2022-04-18 16:23:22.527773: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2022-04-18 16:23:22.537982: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "c:\masksdetection-master\Face_recog.py", line 33, in <module>
    for img in os.listdir(path):
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\\masksdetection-master//Recog_Train/.DS_Store/'

原文链接:https://stackoverflow.com//questions/71910908/notadirectoryerror-winerror-267-the-directory-name-is-invalid-c-masksdete

回复

我来回复
  • High-Octane的头像
    High-Octane 评论

    看起来像路径错误,请尝试使用以下 2 个解决方案:

    如果您的文件位于同一运行目录中,这应该可以工作

    import os
    from pathlib import Path
    
    img_path = os.path.join(os.getcwd(), "Recog_Train")
    

    但理想情况下,如果文件位于项目目录中,我建议在下面使用它,因为它允许您从任何地方运行。

    import os
    from pathlib import Path
    
    img_path = os.path.join(str(Path(__file__).parent), "Recog_Train")
    
    2年前 0条评论
  • Miscellaneous的头像
    Miscellaneous 评论

    你混合了不同的斜线,"//""/""\\"

    仅使用"\\"

    请将您的代码发布为我们可以复制和粘贴的格式化代码。永远不要发布代码的图像。

    2年前 0条评论