Why does MATLAB error with "Unable to resolve name" when trying to use Python on a Linux machine?
조회 수: 18 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2020년 3월 2일
편집: MathWorks Support Team
2023년 11월 16일
On RHEL 6.5 Linux machine with Python 3.6.6 installed, I get the following error while using the "py.list" and "pyrun" command:
>> pyenv('Version', '/usr/local/pkg/python/3.6.6/bin/python3.6');
>> py.list({'hi'})
Unable to resolve name py.list.
>> pyrun("print('Hello World')")
Error using feval
Unrecognized function or variable 'py.dict'.
My MATLAB "pyenv" looks like this and I notice that the "Library" field is empty:
>> 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
채택된 답변
MathWorks Support Team
2024년 12월 17일 0:00
편집: MathWorks Support Team
2023년 11월 16일
On Linux and Mac systems, if the "Library" field is empty in the "pyenv" output, it indicates that Python was installed without the "--enable-shared" option. 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:
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 Python Environment 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
Note that the "Library" field now contains the library information. And you should now be able to make calls to Python such as the following:
>> py.list({'hello', 'world'})
ans =
Python list with no properties.
['hello', 'world']
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!