How can I execute python code in virtualenv from matlab

I am creating a Matlab toolkit for research, and I need to execute Matlab code, but also Python code.

I want to allow the user to execute Python code from Matlab. The problem is that if I do this right away, I will have to install everything in the Python environment and I want to avoid this using virtualenv. The problem is that I do not know how to tell Matlab to the user about creating a virtual environment.

+4
source share
1 answer

You can change the environment variable PATHin MATLAB before calling python from MATLAB

% Modify the system PATH so it finds the python executable in your venv first
setenv('PATH', ['/path/to/my/venv/bin', pathsep, getenv('PATH')])

% Call your python script
system('python myscript.py')

Or the best way would be to specify the full path to the python binary

system('/path/to/my/venv/bin/python myscript.py')
+6
source

Source: https://habr.com/ru/post/1654845/


All Articles