python import: dll or dependecies not found from Matlab environment
Mostrar comentarios más antiguos
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 comentarios
Binxu Wang
el 30 de En. de 2023
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
el 9 de Feb. de 2023
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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Call Python from MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!