Import Python user modules from Matlab

Setup Matlab to use your user Python install (e.g. Anaconda Python) and import your own modules (e.g. some Python module you made yourself or got from Github). Here we assume you have Anaconda/Miniconda Python 3.6 with Matlab R2017b.

  1. setup your user module. Let’s say you want to use ESPRIT in Python from Matlab

     git clone
     cd signal_subspace
     python develop
  2. from within Matlab

     pyversion ~/miniconda/bin/python

    Python Error: TypeError: esprit() missing 2 required positional arguments: ‘x’ and ‘L’


  • you do not import Python modules with Matlab, the Python module import is implicit in the module function call
  • Python executable choice persists across Matlab sessions.


Troubleshooting Python not found

If you get

Error using pyversion Path argument does not specify a valid executable.

To fix by manually overriding the Python executable path, in your matlab.settings (on Linux, this is under ~/.matlab/R2017b/matlab.settings (assuming Linux username joe) you must have a section like:

<settings name="external">
    <settings name="interfaces">
        <settings name="python">
            <key name="Version">
                <string minArraySize="4" maxArraySize="4">


Your can force Python 3.6 to work with older versions of Matlab < R2017b this way.





Leave a Comment