一、问题描述
本人希望能通过Python调用Matlab引擎 (参考文章 python调用matlab程序 pycharm),在输入 python setup.py install 命令时出现问题。
(py37_env) D:\Program Files\MATLAB\R2019b\extern\engines\python>python setup.py install
C:\Users\17825\anaconda3\envs\py37_env\lib\site-packages\setuptools\dist.py:547: UserWarning: The version specified ('R2019b') 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.
"details." % version
C:\Users\17825\anaconda3\envs\py37_env\lib\site-packages\setuptools\command\install.py:37: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
setuptools.SetuptoolsDeprecationWarning,
C:\Users\17825\anaconda3\envs\py37_env\lib\site-packages\setuptools\command\easy_install.py:147: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
EasyInstallDeprecationWarning,
C:\Users\17825\anaconda3\envs\py37_env\lib\site-packages\pkg_resources\__init__.py:126: PkgResourcesDeprecationWarning: r2019b is an invalid version and will not be supported in a future release
PkgResourcesDeprecationWarning,
C:\Users\17825\anaconda3\envs\py37_env\lib\site-packages\pkg_resources\__init__.py:126: PkgResourcesDeprecationWarning: r2021a is an invalid version and will not be supported in a future release
PkgResourcesDeprecationWarning,
C:\Users\17825\anaconda3\envs\py37_env\lib\site-packages\pkg_resources\__init__.py:126: PkgResourcesDeprecationWarning: R2019b is an invalid version and will not be supported in a future release
PkgResourcesDeprecationWarning,
C:\Users\17825\anaconda3\envs\py37_env\lib\site-packages\setuptools\command\egg_info.py:647: SetuptoolsDeprecationWarning: Custom 'build_py' does not implement 'get_data_files_without_manifest'.
Please extend command classes from setuptools instead of distutils.
SetuptoolsDeprecationWarning
zip_safe flag not set; analyzing archive contents...
matlab.__pycache__.__init__.cpython-37: module references __file__
matlab.__pycache__.__init__.cpython-37: module references __path__
matlab.engine.__pycache__.__init__.cpython-37: module references __file__
二、解决方案
原因是setuptools版本过高。setuptools在58.0版本以后弃用了一些方法,导致matlab.engine中的一些命令无法运行。在cmd中输入如下命令将setuptools降版本至58.0版本即可。
pip install setuptools==58.0
在安装完成后,再次运行 python setup.py install 命令,看到如下内容时,安装成功。
running install
running build
running build_py
running install_lib
....
Writing C:\Users\17825\anaconda3\envs\py37_env\Lib\site-packages\matlabengineforpython-R2019b-py3.7.egg-info