How to add the path to a local python file to be executed by a Matlab script?

Hi,
I want to execute a python function from a Matlab script. How can I add the path to the local python file to be visible to the Matlab script?
Thanks

 채택된 답변

Jaime Trivino
Jaime Trivino 2021년 9월 15일
I have founf that we can define the path to our own python environment (conda)
pyenv("Version","C:\path to\anaconda3\envs\myenv\python.exe")

추가 답변 (2개)

Yongjian Feng
Yongjian Feng 2021년 9월 12일
Python uses an env var called PYTHONPATH to point to packages/scripts. So inside matlab, you just need to add the path you want to that env var following this: set env var

댓글 수: 3

Thank you Yongjian. I found an easier solution by changing pyenv 'Version'
@Jaime Trivino Was your problem related to python environment ?
I am running my scripts just if I keep them in the current path folder, but when I use addpath() it does not work anymore... Was this the problem you had, if so how did you fix it?
Best,
Emil
Found solution. Posting it.

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

Emil Skoglund
Emil Skoglund 2023년 1월 14일
You need to use this function to add the path of the folder istead of the addpath().
https://se.mathworks.com/matlabcentral/fileexchange/62703-py_addpath-directory-matlab_too

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

질문:

2021년 9월 10일

답변:

2023년 1월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by