필터 지우기
필터 지우기

python environment on matlab

조회 수: 20 (최근 30일)
Raza
Raza 2024년 3월 5일
댓글: Karl 2024년 3월 6일
Hello,
I am trying to use python on matlab. To load the python environment I am giving the python executable file to pyenv() command as follows:
pyenv(Version="/Users/raza/anaconda3/bin/python")
% Check if the current MATLAB working directory is in the Python path
if count(py.sys.path, pwd) == 0
insert(py.sys.path, int32(0), pwd);
end
It shows me the ouput with python environment but it doesn't recognize py command and shows error as follows:
ans =
PythonEnvironment with properties:
Version: "3.11"
Executable: "/Users/raza/anaconda3/bin/python"
Library: "/Users/raza/anaconda3/lib/libpython3.11.dylib"
Home: "/Users/raza/anaconda3"
Status: NotLoaded
ExecutionMode: InProcess
Unable to resolve the name 'py.sys.path'.
Could someone please guide me, is it due to the fact that python doesn't get loaded?
System info - macOS (venture 13.6) Apple M2 Pro
Matlab version - R2023b update 7

답변 (1개)

Karl
Karl 2024년 3월 5일
The error message indicates a failure in the call to sys.path. There are some hints on troubleshooting this type of failure at:
  댓글 수: 2
Raza
Raza 2024년 3월 6일
Thank you, the problem is when I do simply pyenv("python3") it works it gets loaded. However when I use specific python version installed through anaconda it doesn't get loaded, even though I tried different versions with separate conda environments.
Karl
Karl 2024년 3월 6일
In case you haven't done so already, the following could be worth checking:
  1. Do your anaconda Python builds match your MATLAB build? For information about this, specific to macOS with Apple Silicon, see: https://mathworks.com/matlabcentral/answers/1977529-how-to-use-python-from-matlab-on-mac-with-apple-silicon
  2. Do you have the PYTHONHOME environment variable either unset or set to match the Python version of pyenv? For information about this, see the last paragraph of: https://mathworks.com/help/matlab/matlab_external/install-supported-python-implementation.html
  3. Is there anything in your setting for the PATH environment variable that could be creating conflicts?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by