Why do I get a "Python commands require a supported version of CPython." error when I have a compatible version installed?
349 ビュー (過去 30 日間)
古いコメントを表示
Oliver Scienti
2023 年 3 月 17 日
編集済み: MathWorks Support Team
2023 年 9 月 26 日
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 件のコメント
採用された回答
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.
0 件のコメント
その他の回答 (1 件)
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.
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!