使用matlab调用python文件,首先如果你有虚拟环境,先使用pyenv,路径为你的虚拟环境,
使用pyrunfile函数运行你的python文件
pyenv("Version","C:\Users\2023\.conda\envs\pytorch\python.exe");
pyrunfile("D:\file\predit.py")
但是却报错
Error using __init__><module>
Python Error: OSError: [WinError 127] The specified procedure could not be found. Error
loading "C:\Users\DELL\anaconda3\envs\myenv\lib\site-packages\torch\lib\shm.dll" or one of
its dependencies.
Error in <string>><module> (line 1)
错误使用 __init__><module>
Python 错误 OSError: [WinError 127] 找不到指定的程序。 Error loading
"C:\Users\2023\.conda\envs\hjxpytorch\lib\site-packages\torch\lib\nvfuser_codegen.dll" or one of its dependencies.
需要设置pyenv 将其放在单独进程中运行
pyenv(ExecutionMode="OutOfProcess");
MATLAB 可以在单独的进程中运行 Python 脚本和函数。通过在单独的进程中运行 Python,您可以:
-
在 Python 代码中使用一些与 MATLAB 不兼容的第三方库。
-
将 MATLAB 进程与 Python 代码中的崩溃隔离开来。