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

347 次查看(过去 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
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