【问题标题】:FileNotFoundError: The system cannot find the file specifiedFileNotFoundError:系统找不到指定的文件
【发布时间】:2017-08-28 22:04:07
【问题描述】:

我正在尝试列出输入文件夹中存在的文件:

from subprocess import check_output
print(check_output(["ls", "../input"]).decode("utf8"))

我收到此错误(使用 Python 3):

C:\Users\Tristan\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
    988                                          env,
    989                                          cwd,
--> 990                                          startupinfo)
    991             finally:
    992                 # Child is launched. Close the parent's copy of those pipe

FileNotFoundError: [WinError 2] The system cannot find the file specified

【问题讨论】:

    标签: python python-3.x


    【解决方案1】:

    ls 在 Windows 中不作为命令存在,因此出现错误;它找不到名为ls 的可执行文件来运行。这个类似问题的解决方案应该可以帮助你做你想做的事:How to use Subprocess in Windows

    【讨论】:

      【解决方案2】:

      感谢Izaak Weiss的回答,解决办法变成:

      import os
      l = os.listdir("input")
      print (l)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-05-21
        • 1970-01-01
        • 1970-01-01
        • 2020-01-02
        • 1970-01-01
        • 2017-08-01
        • 2019-07-29
        相关资源
        最近更新 更多