Borrar filtros
Borrar filtros

Invalid version R2021 when installing for Python 3.7-3.9

120 visualizaciones (últimos 30 días)
Anastasios
Anastasios el 20 de Jul. de 2023
Respondida: Juntao el 14 de Mzo. de 2024
I use MATLAB R2021b, Python 3.7 or 3.9 and setuptools==60.2.0 . I run as admin and I am trying to setup MATLAB for python as matlab-engine.
In all cases that I run (python setup.py install) on the command line i get the error:
File "C:\Users\...\envs\xxx\lib\site-packages\setuptools\_vendor\packaging\version.py", line 198, in __init__
raise InvalidVersion(f"Invalid version: '{version}'")
setuptools.extern.packaging.version.InvalidVersion: Invalid version: 'R2021b'
Any ideas how to fix this? I am on Windows 10 Enterprise. What can be the problem with the versions?

Respuestas (3)

Kshittiz
Kshittiz el 24 de Jul. de 2023
Hey,
The error you are facing can be due to an issue with the version parsing in the packaging library used by setuptools. The library doesn't recognize the version string 'R2021b' as a valid format.
To resolve this problem, you can try the following steps:
  1. Update setuptools to the latest version using the command python -m pip install --upgrade setuptools.
  2. Make sure you have the correct version of the MATLAB Engine for Python installed, which is compatible with your MATLAB version (R2021b). You can download it from the MathWorks website.
  3. Verify that your Python environment is using the correct MATLAB installation. Set the MATLAB root directory by running set MATLAB_ROOT=<path_to_matlab_root>, replacing <path_to_matlab_root> with the actual MATLAB installation directory.
  4. Retry the installation of the MATLAB Engine for Python using either python setup.py install or pip install matlab-engine in the command line.
I hope this helps.
Thanks
  1 comentario
Anastasios
Anastasios el 26 de Jul. de 2023
Thank you for your answer, it was very helpful. I checked various setuptools versions but did not work with python setup.py install. What it did work was :
python -m pip install matlabengine==9.11.21
and i used 9.11.21 as the appropriate matlab- engine. Now it works, although i don't know what is the difference between doing setup.py install and install matlabengine.

Iniciar sesión para comentar.


Vinay Kulkarni
Vinay Kulkarni el 9 de Oct. de 2023
This one worked for me
python -m pip install matlabengine==9.11.21

Juntao
Juntao el 14 de Mzo. de 2024
I have the same problem, I use MATLAB2021a and Python3.8, setuptools 69.2.0,and when I follow the offical guide for installation of matlabengine,then I get ERROR with: setuptools.extern.packaging.version.InvalidVersion: Invalid version: 'R2021a' , But I reslove it by downgrade setuptools to setuptools-65.0.0 by using pip install setuptools==65.0.0. hope to be helpful.

Categorías

Más información sobre Call MATLAB from Python en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by