MATLAB: Does MATLAB error with “Unable to resolve name” when trying to use Python

MATLAB

On RHEL 6.5 Linux machine with Python 3.6.6 installed, I get the following error:
>> pyenv('Version', '/usr/local/pkg/python/3.6.6/bin/python3.6');
>> py.list({'hi'})
Unable to resolve name py.list.
My MATLAB pyenv looks like this:
>> pyenv
Version: "3.6"
Executable: "/usr/local/pkg/python/3.6.6/bin/python3.6"
Library: ""
Home: "/usr/local/pkg/python/3.6.6"
Status: NotLoaded
ExecutionMode: InProcess

Best Answer

The Python installation was built without shared libraries enabled, so MATLAB cannot interact with CPython properly. According to this documentation, Python must be built using the "--enable-shared option".
1) Please rebuild the Python executable using the "--enable-shared" option.
This way MATLAB will be able to interact with Python through the shared library file, such as "libpython3.6.so.1.0".
After re-installation of Python with the build configured properly, the MATLAB PythonEnvironment should look similar to:
>> pyenv
Version: "3.6"
Executable: "/usr/local/pkg/python/3.6.6/bin/python3.6"
Library: "libpython3.6.so.1.0"
Home: "/usr/local/pkg/python/3.6.6"
Status: NotLoaded
ExecutionMode: InProcess
And you should now be able to make calls to python such as
>> py.list({'hello', 'world'})
ans =
Python list with no properties.
['hello', 'world']