If you’ve tried recently to install matlab engine on a Python 3.6, you’ve seen a message saying that the platform is not supported. That doesn’t make any sense, since Python 3.5 is supported, right?
The problem is that Mathworks hardcodes a list with valid versions, I guess to reduce pressure on their customer service in case something goes wrong with untested versions. Well, that doesn’t mean that we shouldn’t be allowed to try it anyway, right?
All we have to do is modify the offending harcoded files (if we have write permission. On a server we’d have to copy files and change some hardcoded paths as well.)
Assuming we have write permission to change matlab’s install scripts, these are the changes to support 3.6:
In the file engines/python/build/lib/matlab/engine/__init__.py
, change the
list _supported_versions
by appending the string '3_6'
_supported_versions = ['2_7', '3_3', '3_4', '3_6']
Do the same for file engines/python/dist/matlab/engine/__init__.py
and for engines/python/setup.py
There is a compiled library for your architecture and for your python version. On a Mac, for example,
that binary is called /engines/python/dist/matlab/engine/maci64/matlabengineforpython3_4.so
.
Make a copy and rename it to your python version:
engdir=engines/python/dist/matlab/engine/maci64 cp ${engdir}/matlabengineforpython3_4.so ${engdir}//matlabengineforpython3_6.so
Open the binary in any binary editor and change all references from 3.4 to 3.6 and all references from 3_4 to 3_6. If everything goes well, running the following command on the extern/engines/python
directory should return only 3 entries:
find /Applications/MATLAB_R2015b.app/extern/engines/python -type f -exec grep -l "3_4" {} \;
To install, simply follow the instructions in the Matlab website:
python3 setup.py install
Fire up your python3.6 and try the following:
import sys
print(sys.version)
import matlab.engine
eng = matlab.engine.start_matlab()
print(eng.sqrt(4.))
Ops, for me it shows “Module use of python35.dll conflicts with this version of Python.”
Seems this approach dosen't work for me
UPDATE:
I forgot to change one python35.dll to python36.dll. And after I changed it, it works well.
Thanks so much