导入environment.yml时matlabengineforpython==R2020b安装失败求助
问题:导入conda环境时matlabengineforpython==R2020b安装失败
执行conda env create -f environment.yml创建环境时,pip无法找到matlabengineforpython==R2020b包,报错:
ERROR: Could not find a version that satisfies the requirement matlabengineforpython==R2020b (from versions: none) ERROR: No matching distribution found for matlabengineforpython==R2020b
完整执行日志如下:
C:\\Software\\srv569>conda env create -f environment.yml Collecting package metadata (repodata.json): done Solving environment: done ==> WARNING: A newer version of conda exists. <== current version: 22.9.0 latest version: 22.11.0 Please update conda by running $ conda update -n base -c defaults conda Preparing transaction: done Verifying transaction: done Executing transaction: done Installing pip dependencies: \\ Ran pip subprocess with arguments: ['C:\\Software\\srv569\\Anaconda3\\envs\\research_projects\\python.exe', '-m', 'pip', 'install', '-U', '-r', 'C:\\Software\\srv569\\condaenv.0oaiyh7x.requirements.txt'] Pip subprocess output: Collecting absl-py==1.0.0 Using cached absl_py-1.0.0-py3-none-any.whl (126 kB) ...(省略中间包安装日志) Collecting markupsafe==2.1.1 Using cached MarkupSafe-2.1.1-cp38-cp38-win_amd64.whl (17 kB) Pip subprocess error: ERROR: Could not find a version that satisfies the requirement matlabengineforpython==R2020b (from versions: none) ERROR: No matching distribution found for matlabengineforpython==R2020b failed CondaEnvException: Pip failed
解决方案
matlabengineforpython不会上传到公共PyPI源,必须依赖本地安装的对应版本MATLAB才能安装,按以下步骤处理:
步骤1:确认台式机已安装MATLAB R2020b
若未安装,需先安装MATLAB R2020b版本,确保安装时勾选了"MATLAB Engine for Python"组件(默认一般会勾选)。步骤2:手动安装MATLAB Python引擎
- 激活目标conda环境:
conda activate research_projects - 找到MATLAB安装目录下的Python引擎路径,默认路径类似:
C:\Program Files\MATLAB\R2020b\extern\engines\python - 进入该目录,执行安装命令:
python setup.py install
- 激活目标conda环境:
步骤3:跳过pip依赖先创建环境(可选)
如果不想中断环境创建流程,可以先跳过pip依赖创建基础环境,再手动安装引擎:conda env create -f environment.yml --no-pip激活环境后重复步骤2的手动安装流程。
步骤4:修改environment.yml(如果不需要对应版本引擎)
若不需要MATLAB R2020b的引擎,可直接编辑environment.yml,移除matlabengineforpython==R2020b的条目,再重新执行conda env create -f environment.yml,之后按需安装兼容的MATLAB引擎版本。
内容的提问来源于stack exchange,提问作者carsof
相关产品推荐
相关产品推荐

