Error using subprocess​>_execute_​child (line 1311) Python Error: FileNotFoundError: [WinError 2] The system cannot find the file specified

36 ビュー (過去 30 日間)
Kfir Weissman
Kfir Weissman 2022 年 2 月 9 日
回答済み: carl hyde 2023 年 2 月 7 日
when i call to my python script from matlab i fet this error:
Error using subprocess>_execute_child (line 1311)
Python Error: FileNotFoundError: [WinError 2] The system cannot find the file specified
Error in subprocess>__init__ (line 858)
Error in utils>mediainfo_json (line 274)
Error in audio_segment>from_file (line 728)
how can i fix it?

回答 (2 件)

Yongjian Feng
Yongjian Feng 2022 年 2 月 9 日
Most of the times, this kind of error can be fixed by setting the env var PYTHONPATH inside matlab.
So figure out what file/package python has trouble to find, figure out where it is, and then add it to the PYTHONPATH env var inside matlab.

carl hyde
carl hyde 2023 年 2 月 7 日
When you specify the file name "filename.ext" while read file, you are providing the open() function with a relative path. This means that the file you want to read is located in the current working directory.
file = open('filename.ext') //relative path
In the above code, you are not giving the full path to a file to the open() function, just its name - a relative path. The error “FileNotFoundError: [Errno 2] No such file or directory” is telling you that there is no file of that name in the working directory. So, try using the exact, or absolute path.
file = open(r'C:\path\to\your\filename.ext') //absolute path
In the above code, all of the information needed to locate the file is contained in the path string - absolute path.
If the full path to the file is not provided, the python file path is interpreted relative to the current working directory. This is the directory from which the program was started. For this to work, the directory containing the python executable must be in the PATH environment variable, which contains directories automatically searched for executables when a command is entered. To access a file in a different directory, you must either specify a relative path between the files or use an absolute path for one of them.

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by