MATLAB Answers


Using Matlab in Python

I'm trying to execute matlab functions in python using the Matlab python package. However, when running an example from the documentation, I am getting an error message. When I run the code:
import matlab
import matlab.engine
eng = matlab.engine.start_matlab()
a = matlab.double([1,4,9,16,25])
b = eng.sqrt(a)
I get the error message:
File "<ipython-input-7-6ccc095b323c>", line 1, in <module>
runfile('/Users/rach/Google Drive/PHD/Programming/Winds/', wdir='/Users/rach/Google Drive/PHD/Programming/Winds')
File "//anaconda/envs/netcdf/lib/python2.7/site-packages/spyder/utils/site/", line 866, in runfile
execfile(filename, namespace)
File "//anaconda/envs/netcdf/lib/python2.7/site-packages/spyder/utils/site/", line 94, in execfile
builtins.execfile(filename, *where)
File "/Users/rach/Google Drive/PHD/Programming/Winds/", line 4, in <module>
a = matlab.double([1,4,9,16,25])
File "//anaconda/envs/netcdf/lib/python2.7/site-packages/matlab/", line 51, in __init__
raise ex
TypeError: 'NoneType' object is not callable
What does this error mean? Is it something to do with how I have installed everything?
Thanks, Rachael


Sign in to comment.


1 Answer

Answer by Nagarjuna Manchineni on 15 May 2017
 Accepted Answer

Looking at the error message, I can see that you are using the python from the Anaconda distribution. This version of Python is not supported with MATLAB. CPython is the recommended Python distribution for use with MATLAB Engine for Python, as noted at the following links:
I believe once you install the correct version you will not encounter the same issue.

  1 Comment

Ahh I see... Thank you. I have got it to work with my version - I just have to restart the kernal everytime I want to run the code. It's definitely not ideal but got my code to work!

Sign in to comment.