文件未找到错误:[WinError 3]系统找不到指定的路径:

10
我正在尝试运行来自此教程的代码。我已经将代码和数据集放在同一个目录下,但是仍然出现以下错误。
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-6-5f5284db0527> in <module>()
     39 # extract features from all images
     40 directory = 'Flicker8k'
---> 41 features = extract_features(directory)
     42 print('Extracted Features: %d' % len(features))
     43 # save to file

<ipython-input-6-5f5284db0527> in extract_features(directory)
     18         # extract features from each photo
     19         features = dict()
---> 20         for name in listdir(directory):
     21                 # load an image from file
     22                 filename = directory + '/' + name

**FileNotFoundError: [WinError 3] The system cannot find the path specified: 'Flicker8k'**
4个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
10
系统无法找到指定的路径: 'Flicker8k'。尝试将相对目录路径 directory = 'Flicker8k' 替换为 Flicker8k 目录的完整绝对路径(看起来你正在使用 Windows,因此类似于 C:\myproject\Flicker8k,如果你是在 Linux 上,则是 /home/user/myproject/Flicker8k 或数据集所在的任何位置)。 因此,请确保:
  • 使用绝对路径而不是相对路径
  • 文件夹(有正确的大小写)存在
  • 数据集实际上在该文件夹中
  • 文件夹(以及其中的文件)的访问权限没有问题

1
我按照您的建议将我的路径从“directory = Flicker8k”更改为“directory = C:// user // abbas // Flicker8k”,这对我有用。谢谢! - abbas khan

7

对于有同样错误的人。

如果你尝试在system32中列出文件夹,但python告诉你:

FileNotFoundError:[WinError 3]系统找不到指定的路径:“C:\ Windows \ System32 \ OpenSSH \”

这是由于使用了python-32bit。安装64位的python将解决问题。

浪费了一整天来解决它。

最好的资料解释 :)

https://mail.python.org/pipermail/python-win32/2012-March/012121.html

Python无法找到System32

This is a very confusing point, so even though it's not directly Python-related, I think it's still valuable to discuss it again.

As you discovered, Windows is helping you. For reasons that have never been adequately explained to me (and believe me, I have asked people who ought to know), on a 64-bit system, all of the 64-bit commands and DLLs live in \Windows\System32. All of the 32-bit commands and DLLs live in \Windows\SysWOW64. A 64-bit process gets to see both of those directories as they really are.

But for a 32-bit process, the operating system "helpfully" rewrites your paths. When you refer to \Windows\System32, the system helpfully rewrites that reference to \Windows\SysWOW64. Microsoft calls it file system redirection". I call it "file system stupidity".

Most of the time, that's OK. Most of the important commands are present in both directories. A few (like nbtstat) are not, and that's a problem.

There are two solutions. One is to use 64-bit Python, which you have said is a problem for you. The other is to use an API with the tongue-twisting name Wow64DisableWow64FsRedirection. Here is my script:

   import ctypes
    k32 = ctypes.windll.kernel32
    wow64 = ctypes.c_long( 0 )
    k32.Wow64DisableWow64FsRedirection( ctypes.byref(wow64) )
    # ... do stuff with real files ...
    k32.Wow64RevertWow64FsRedirection( wow64 )

2

如果您正在使用某个环境,并且不想更改代码中的所有路径,则可以在顶部执行以下操作:

import os
os.chdir('<path URL>')

eg.

import os
os.chdir('C:/Users/DELL/Desktop/projectfolder')

0
有时候会出现“文件未找到”错误,这是因为文件路径太长了。你可以通过在文件路径前添加"\\\\?\\"来解决这个问题;例如 + "\\\\?\\" + os.path

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,