MATLAB Answers

Changing Python Environment used by MATLAB

26 views (last 30 days)
Furqan Hashim
Furqan Hashim on 9 Aug 2020
I have mutiple python enviroments on a windows server. I need to change the Python enviroment that MATLAB is using. MATLAB version that I am using is 2017b and I've used the command pyversion('/path/to/python/venv') to change python environment being used by MATLAB. This command gives an error
Python is loaded. The version cannot be changed in this MATLAB session. To change the version, restart MATLAB, and then call 'pyversion'.
To deal with the above error I've made changes to startup.m file by changing two variables
pyPath = '/path/to/python/venv';
pyLibPath = [pyPath 'Lib\site-packages\projects'];
After making changes and restarting MATLAB I get an error
Unable to set Python environment to /path/to/python/venv in this session.
Please restart MATLAB!
I suspect that if results from command py.sys.path contains any path with directory that refers to old python environment I won't be able to set new Python environment. E.g. if the result from command py.sys.path is
['/path/to/python/venv', '','/path/to/python/old_venv']
I need to remove '/path/to/python/old_venv' using remove(py.sys.path, '/path/to/python/old_venv'). I did that but when I restart MATLAB after doing that I see that output from py.sys.path does not change as it still contains '/path/to/python/old_venv'. To be sure that older python paths are removed from py.sys.path I've ran following commands in new Python environment
import sys
sys.path
Output from above doesnot contain any paths from older Python environment.
Can someone provide a solution on how can I change the Python environment being used by MATLAb?
I've mentioned all the things that I've tried.

  0 Comments

Sign in to comment.

Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by