Why do I get a "Python commands require a supported version of CPython." error when I have a compatible version installed?

조회 수: 349 (최근 30일)
Hello, I am trying to run python commands in matlab. I have installed Matlab version 2023a and Python 3.10.0, which should be compatible according to the documentation here Versions of Python Compatible with MATLAB Products by Release - MATLAB & Simulink (mathworks.com). I have run the setup.py command in the "...\extern\engines\python folder" as required, and the error message about not recognising py.list has disappeared, indicating the install was successful. I now get an error message saying "Python commands require a supported version of CPython" when I type "py.list", despite having a compatible version ("pyenv" returns version 3.10). Can anyone suggest anything else I could try? Thanks, Olie

채택된 답변

MathWorks Support Team
MathWorks Support Team 2023년 9월 26일
편집: MathWorks Support Team 2023년 9월 26일
There are two ways to use Python with MATLAB:
Running the setup.py command in the "...\extern\engines\python folder", is one way to enable running MATLAB commands from Python (item 2, above), but does not configure MATLAB to run Python commands (item 1, above), like py.list.
To configure your system to run Python commands from MATLAB, see this documentation: Configure Your System to Use Python.
The fact that pyenv shows a compatible version (3.10), but you see the "Python commands require a supported version of CPython" error, may indicate one of the following issues, depending on your platform.
Windows: You may have installed Python from the Microsoft store. MATLAB does not support CPython versions from the Microsoft store. If this is the case, install a distribution, such as those found at https://www.python.org/downloads/. If MATLAB does not recognize the new Python installation (you can see this by running the command >>pyenv), then see these instructions for setting the Python version.
Linux and Mac: You may have installed Python without configuring the build with the "--enable-shared" flag. If this is the case, reinstall Python with this flag enabled. If MATLAB does not recognize the new Python installation (you can see this by running the command >>pyenv), then see these instructions for setting the Python version.

추가 답변 (1개)

Adithya
Adithya 2023년 3월 27일
It's possible that your MATLAB installation is not detecting your Python installation properly. Here are a few things you can try:
1. Check that your Python installation is in your system's PATH environment variable. You can do this by opening a command prompt or terminal and typing "python". If Python starts up, then it's in your PATH.
2. In MATLAB, try running the following command to check which Python interpreter MATLAB is using:
>>pyversion
3.Try reinstalling the MATLAB Engine API for Python. To do this, open a command prompt or terminal and navigate to the "...\extern\engines\python" folder. Then run the following command:
>>python setup.py install --prefix=<matlab_root>/extern/engines/python
Be sure to replace "<matlab_root>" with the root directory of your MATLAB installation.
4. If the above steps don't work, you can try adding the path to your Python executable manually in MATLAB. You can do this by running the following command:
pyversion('path/to/python')
Hopefully one of these solutions works for you.

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by