Why do I get a "Python commands require a supported version of CPython." error when I have a compatible version installed?
346 views (last 30 days)
Show older comments
Oliver Scienti
on 17 Mar 2023
Edited: MathWorks Support Team
on 26 Sep 2023
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
0 Comments
Accepted Answer
MathWorks Support Team
on 26 Sep 2023
Edited: MathWorks Support Team
on 26 Sep 2023
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.
0 Comments
More Answers (1)
Adithya
on 27 Mar 2023
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.
0 Comments
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!