How can I execute Python code in a virtualenv from Matlab
<p>I am creating a Matlab toolbox for research and I need to execute Matlab code but also Python code. </p>

<p>I want to allow the user to execute Python code from Matlab. The problem is that if I do it right away, I would have to install everything on the Python's environment and I want to avoid this using virtualenv. The problem is that I don't know how to tell Matlab to user the virtual enviornment created.</p>

<p>You can either modify the <code>PATH</code> environment variable in MATLAB prior to calling python from MATLAB</p>

<pre class="lang-matlab prettyprint-override"><code>% 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')
</code></pre>

<p>Or the better way would be to specify the full path to the python binary</p>

<pre><code>system('/path/to/my/venv/bin/python myscript.py')
</code></pre>

python matlab virtualenv