python import: dll or dependecies not found from Matlab environment
显示 更早的评论
Calling python scripts or functions from matlab has an error at certain import statements, the error is at
py.importlib.import_module('torch')
and equivalents.
Python Error: OSError: [WinError 127] The specified procedure could not be found. Error loading
"C:\Users\jklebes\Miniconda3\envs\myenv\lib\site-packages\torch\lib\shm.dll" or one of its dependencies.
pytorch is installed in the conda environment and can be loaded and run fine in the conda shell in python. The dll exists in the correct location. I don't need to conda or pip reinstall pytorch, because outside of the matlab environment (using python) everything works.
Within matlab, the correct python path is set and other modules in similar locations can be imported, for example
py.importlib.import_module('numpy')
, taking from "C:\Users\jklebes\Miniconda3\envs\myenv\lib\site-packages\numpy", is fine.
I have tried copying everything from system PATH, in an environment where the imports work, using
setenv("PATH", ...)
The PATH in matlab is now the same as in the command prompt, which should in my understanding enable the same DLL to be found by python _frozen_importlib running in an identical environment. Still I get the error that the DLL or its dependencies are not found.
2 个评论
Binxu Wang
2023-1-30
I have the exact same problem as you did, and I tried the exact same method as you did (copying the env variables exactly). I also have no luck.
I'm also querying the official support team to see if there is a known solution....
Thanks for raising this up.
Sivylla Paraskevopoulou
2023-2-9
Maybe setting a Python virtual environment in your working folder will help. For an example on how to set a virtual environmnent and calling PyTorch from MATLAB, see Call Python from MATLAB to Compare PyTorch Models for Image Classification.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!