python中使用matlab时显示版本错误
一、问题描述
本人希望能通过Python调用Matlab引擎 (参考文章 python调用matlab程序 pycharm),在输入 python setup.py install 命令时出现问题。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | (python38) D:\Program Files\MATLAB\R2021b\extern\engines\python>python setup.py install - - user E:\anconda3\envs\python38\lib\site - packages\setuptools\dist.py: 543 : UserWarning: The version specified ( 'R2021b' ) is an invalid version, this may not work as expected with newer versions of setuptools, pip, and PyPI. Please see PEP 440 for more details. warnings.warn( E:\anconda3\envs\python38\lib\site - packages\setuptools\command\install.py: 34 : SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards - based tools. warnings.warn( E:\anconda3\envs\python38\lib\site - packages\setuptools\command\easy_install.py: 144 : EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards - based tools. warnings.warn( Traceback (most recent call last): File "setup.py" , line 80 , in <module> setup( File "E:\anconda3\envs\python38\lib\site-packages\setuptools\_distutils\core.py" , line 185 , in setup return run_commands(dist) File "E:\anconda3\envs\python38\lib\site-packages\setuptools\_distutils\core.py" , line 201 , in run_commands dist.run_commands() File "E:\anconda3\envs\python38\lib\site-packages\setuptools\_distutils\dist.py" , line 969 , in run_commands self .run_command(cmd) File "E:\anconda3\envs\python38\lib\site-packages\setuptools\dist.py" , line 1208 , in run_command super ().run_command(command) File "E:\anconda3\envs\python38\lib\site-packages\setuptools\_distutils\dist.py" , line 988 , in run_command cmd_obj.run() File "E:\anconda3\envs\python38\lib\site-packages\setuptools\command\install.py" , line 74 , in run self .do_egg_install() File "E:\anconda3\envs\python38\lib\site-packages\setuptools\command\install.py" , line 123 , in do_egg_install self .run_command( 'bdist_egg' ) File "E:\anconda3\envs\python38\lib\site-packages\setuptools\_distutils\cmd.py" , line 318 , in run_command self .distribution.run_command(command) File "E:\anconda3\envs\python38\lib\site-packages\setuptools\dist.py" , line 1208 , in run_command super ().run_command(command) File "E:\anconda3\envs\python38\lib\site-packages\setuptools\_distutils\dist.py" , line 987 , in run_command cmd_obj.ensure_finalized() File "E:\anconda3\envs\python38\lib\site-packages\setuptools\_distutils\cmd.py" , line 111 , in ensure_finalized self .finalize_options() File "E:\anconda3\envs\python38\lib\site-packages\setuptools\command\bdist_egg.py" , line 93 , in finalize_options ei_cmd = self .ei_cmd = self .get_finalized_command( "egg_info" ) File "E:\anconda3\envs\python38\lib\site-packages\setuptools\_distutils\cmd.py" , line 305 , in get_finalized_command cmd_obj.ensure_finalized() File "E:\anconda3\envs\python38\lib\site-packages\setuptools\_distutils\cmd.py" , line 111 , in ensure_finalized self .finalize_options() File "E:\anconda3\envs\python38\lib\site-packages\setuptools\command\egg_info.py" , line 219 , in finalize_options parsed_version = parse_version( self .egg_version) File "E:\anconda3\envs\python38\lib\site-packages\pkg_resources\_vendor\packaging\version.py" , line 266 , in __init__ raise InvalidVersion(f "Invalid version: '{version}'" ) pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: 'R2021b' x |
显示错误
二、解决方案
原因是setuptools版本过高。setuptools在58.0版本以后弃用了一些方法,导致matlab.engine中的一些命令无法运行。在cmd中输入如下命令将setuptools降版本至58.0版本即可。
pip install setuptools==58.0
在安装完成后,再次运行 python setup.py install 命令,看到如下内容时,安装成功。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | (python38) D:\Program Files\MATLAB\R2021b\extern\engines\python>python setup.py install - - user running install running build running build_py creating build creating build\lib creating build\lib\matlab copying dist\matlab\mlarray.py - > build\lib\matlab copying dist\matlab\mlexceptions.py - > build\lib\matlab copying dist\matlab\__init__.py - > build\lib\matlab creating build\lib\matlab\engine copying dist\matlab\engine\basefuture.py - > build\lib\matlab\engine copying dist\matlab\engine\engineerror.py - > build\lib\matlab\engine copying dist\matlab\engine\enginehelper.py - > build\lib\matlab\engine copying dist\matlab\engine\enginesession.py - > build\lib\matlab\engine copying dist\matlab\engine\fevalfuture.py - > build\lib\matlab\engine copying dist\matlab\engine\futureresult.py - > build\lib\matlab\engine copying dist\matlab\engine\matlabengine.py - > build\lib\matlab\engine copying dist\matlab\engine\matlabfuture.py - > build\lib\matlab\engine copying dist\matlab\engine\__init__.py - > build\lib\matlab\engine creating build\lib\matlab\_internal copying dist\matlab\_internal\mlarray_sequence.py - > build\lib\matlab\_internal copying dist\matlab\_internal\mlarray_utils.py - > build\lib\matlab\_internal copying dist\matlab\_internal\__init__.py - > build\lib\matlab\_internal running install_lib creating C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab creating C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine copying build\lib\matlab\engine\basefuture.py - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine copying build\lib\matlab\engine\engineerror.py - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine copying build\lib\matlab\engine\enginehelper.py - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine copying build\lib\matlab\engine\enginesession.py - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine copying build\lib\matlab\engine\fevalfuture.py - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine copying build\lib\matlab\engine\futureresult.py - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine copying build\lib\matlab\engine\matlabengine.py - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine copying build\lib\matlab\engine\matlabfuture.py - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine copying build\lib\matlab\engine\_arch.txt - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine copying build\lib\matlab\engine\__init__.py - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine copying build\lib\matlab\mlarray.py - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab copying build\lib\matlab\mlexceptions.py - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab creating C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\_internal copying build\lib\matlab\_internal\mlarray_sequence.py - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\_internal copying build\lib\matlab\_internal\mlarray_utils.py - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\_internal copying build\lib\matlab\_internal\__init__.py - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\_internal copying build\lib\matlab\__init__.py - > C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab byte - compiling C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine\basefuture.py to basefuture.cpython - 38.pyc byte - compiling C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine\engineerror.py to engineerror.cpython - 38.pyc byte - compiling C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine\enginehelper.py to enginehelper.cpython - 38.pyc byte - compiling C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine\enginesession.py to enginesession.cpython - 38.pyc byte - compiling C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine\fevalfuture.py to fevalfuture.cpython - 38.pyc byte - compiling C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine\futureresult.py to futureresult.cpython - 38.pyc byte - compiling C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine\matlabengine.py to matlabengine.cpython - 38.pyc byte - compiling C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine\matlabfuture.py to matlabfuture.cpython - 38.pyc byte - compiling C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\engine\__init__.py to __init__.cpython - 38.pyc byte - compiling C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\mlarray.py to mlarray.cpython - 38.pyc byte - compiling C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\mlexceptions.py to mlexceptions.cpython - 38.pyc byte - compiling C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\_internal\mlarray_sequence.py to mlarray_sequence.cpython - 38.pyc byte - compiling C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\_internal\mlarray_utils.py to mlarray_utils.cpython - 38.pyc byte - compiling C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\_internal\__init__.py to __init__.cpython - 38.pyc byte - compiling C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlab\__init__.py to __init__.cpython - 38.pyc running install_egg_info Writing C:\Users\Lenovo\AppData\Roaming\Python\Python38\site - packages\matlabengineforpython - R2021b - py3. 8.egg - info |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)