Getting and error in setup when installing matlab.engine for Python 3.7.9 with Matlab 2021a

4 views (last 30 days)
The command "python setup.py install" gives me first some warnings and then a Traceback (see below).
I am running the command from the location of setup.py (Program Files\MATLAB\R2021a\extern\engines\python), giving the full path of my python.exe located in a virtual env (D:\repo\seetyzen\embedded\app\env_atd\Scripts as visible in the traceback below).
Warnings:
********************************************************************************
The version specified is not a valid version according to PEP 440.
This may not work as expected with newer versions of
setuptools, pip, and PyPI.
This deprecation is overdue, please update your project and remove deprecated
calls to avoid build errors in the future.
See https://peps.python.org/pep-0440/ for details.
********************************************************************************
and
********************************************************************************
Please avoid running ``setup.py`` directly.
Instead, use pypa/build, pypa/installer or other
standards-based tools.
See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
********************************************************************************
Error
Traceback (most recent call last):
File "setup.py", line 89, in <module>
cmdclass={'build_py': BuildEngine}
File "D:\repo\seetyzen\embedded\app\env_atd\lib\site-packages\setuptools\_distutils\core.py", line 185, in setup
return run_commands(dist)
File "D:\repo\seetyzen\embedded\app\env_atd\lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands
dist.run_commands()
File "D:\repo\seetyzen\embedded\app\env_atd\lib\site-packages\setuptools\_distutils\dist.py", line 969, in run_commands
self.run_command(cmd)
File "D:\repo\seetyzen\embedded\app\env_atd\lib\site-packages\setuptools\dist.py", line 1234, in run_command
super().run_command(command)
File "D:\repo\seetyzen\embedded\app\env_atd\lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
cmd_obj.run()
File "D:\repo\seetyzen\embedded\app\env_atd\lib\site-packages\setuptools\command\install.py", line 80, in run
self.do_egg_install()
File "D:\repo\seetyzen\embedded\app\env_atd\lib\site-packages\setuptools\command\install.py", line 129, in do_egg_install
self.run_command('bdist_egg')
File "D:\repo\seetyzen\embedded\app\env_atd\lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command
self.distribution.run_command(command)
File "D:\repo\seetyzen\embedded\app\env_atd\lib\site-packages\setuptools\dist.py", line 1234, in run_command
super().run_command(command)
File "D:\repo\seetyzen\embedded\app\env_atd\lib\site-packages\setuptools\_distutils\dist.py", line 987, in run_command
cmd_obj.ensure_finalized()
File "D:\repo\seetyzen\embedded\app\env_atd\lib\site-packages\setuptools\_distutils\cmd.py", line 111, in ensure_finalized
self.finalize_options()
File "D:\repo\seetyzen\embedded\app\env_atd\lib\site-packages\setuptools\command\bdist_egg.py", line 92, in finalize_options
ei_cmd = self.ei_cmd = self.get_finalized_command("egg_info")
File "D:\repo\seetyzen\embedded\app\env_atd\lib\site-packages\setuptools\_distutils\cmd.py", line 305, in get_finalized_command
cmd_obj.ensure_finalized()
File "D:\repo\seetyzen\embedded\app\env_atd\lib\site-packages\setuptools\_distutils\cmd.py", line 111, in ensure_finalized
self.finalize_options()
File "D:\repo\seetyzen\embedded\app\env_atd\lib\site-packages\setuptools\command\egg_info.py", line 218, in finalize_options
parsed_version = packaging.version.Version(self.egg_version)
File "D:\repo\seetyzen\embedded\app\env_atd\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: 'R2021a'

Answers (1)

Umeshraja
Umeshraja on 13 Jun 2025
I understand you've been encountering an issue with the MATLAB Engine for Python in MATLAB R2021a related to PEP 440 versioning. I’d like to share that this issue does not occur in R2022b, so I recommend updating to that version or a more recent release if possible.
If updating isn’t an option, there’s a potential workaround you can try in R2021a. You can modify the version value in the setup.py file located at:
<matlabroot>\extern\engines\python\setup.py
Replace the MATLAB release identifier (e.g., "R2021a") with its corresponding PEP 440-compliant version number. For R2021a, this would be 9.10. You can find the appropriate version numbers in the link below:
I hope it helps!

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!