python - 我在子进程python中收到错误“FileNotFoundError:[WinError 2]系统找不到指定的文件”
问题描述
我FileNotFoundError: [WinError 2] The system cannot find the file specified
在子进程 python 中遇到错误。我在堆栈溢出时对其进行了搜索,但没有找到与我的情况相关的任何答案。基本上,我正在尝试通过 python 代码计算视频的持续时间。我在堆栈溢出时对其进行了搜索,并找到了一段代码。当我尝试执行此代码时,我得到FileNotFoundError: [WinError 2] The system cannot find the file specified
. 我检查了一个文件及其路径,它是正确的并且文件是正确的。这是我试图运行的代码,我从这里得到它。
import subprocess
def get_length(filename):
result = subprocess.run(["ffprobe", "-v", "error", "-show_entries",
"format=duration", "-of",
"default=noprint_wrappers=1:nokey=1", filename],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
return float(result.stdout)
get_length("video.avi")
任何建议将不胜感激。这是完整的错误:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-17-8d1ce3720e37> in <module>
9 return float(result.stdout)
10
---> 11 get_length("video.avi")
<ipython-input-17-8d1ce3720e37> in get_length(filename)
6 "default=noprint_wrappers=1:nokey=1", filename],
7 stdout=subprocess.PIPE,
----> 8 stderr=subprocess.STDOUT)
9 return float(result.stdout)
10
~\Anaconda3\envs\FYP\lib\subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
421 kwargs['stdin'] = PIPE
422
--> 423 with Popen(*popenargs, **kwargs) as process:
424 try:
425 stdout, stderr = process.communicate(input, timeout=timeout)
~\Anaconda3\envs\FYP\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
727 c2pread, c2pwrite,
728 errread, errwrite,
--> 729 restore_signals, start_new_session)
730 except:
731 # Cleanup if the child failed starting.
~\Anaconda3\envs\FYP\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)
1015 env,
1016 os.fspath(cwd) if cwd is not None else None,
-> 1017 startupinfo)
1018 finally:
1019 # Child is launched. Close the parent's copy of those pipe
FileNotFoundError: [WinError 2] The system cannot find the file specified
我很困惑为什么我会收到这个错误,尽管我的这段代码运行良好。
import subprocess
process = subprocess.Popen(['vlc', 'video.avi'],
stdout=subprocess.PIPE,
universal_newlines=True)
解决方案
推荐阅读
- javascript - 如何在 React JS 中使用 Scroll 魔法
- css - 具有增长高度的 Flex-box:Chrome 和其他浏览器之间的不同结果
- git - 如何将分支中所有提交的日期更改为现在?
- django - 从 Hyper-V VM 主机物理机访问 VM Django Dev Server
- swift - 带功能/操作器类型的开关/外壳
- c++ - C++ Cmake boost lib不断抛出很多错误
- android - android应用程序数据应该存储在哪里以防止丢失?
- python - 并排条形图
- vba - 在 Excel 中将属性值分配给名称
- python - 找到解决方案时退出递归调用树