在Google Colab中安装Couenne求解器的替代方案咨询
Google Colab中Couenne求解器的替代安装方法(配合Pyomo)
原Ampl开源版Couenne的下载链接已失效,触发如下解压错误:
[couenne-linux64.zip]
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case, the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of couenne-linux64 or
couenne-linux64.zip, and cannot find couenne-linux64.ZIP, period.
可通过以下两种方法在Colab环境中重新安装Couenne并配合Pyomo使用:
方法一:Conda安装(推荐)
Colab默认无Conda环境,先安装Miniconda再从conda-forge源获取Couenne:
- 安装Miniconda到Colab本地
!wget -q https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh !bash Miniconda3-latest-Linux-x86_64.sh -b -f -p /usr/local
- 安装Couenne与Pyomo
!conda install -y -c conda-forge couenne pyomo
- 验证安装有效性
import pyomo.environ as pyo solver = pyo.SolverFactory('couenne') print("Couenne求解器状态:", solver.available())
方法二:GitHub预编译包安装
若Conda安装遇阻,可直接使用COIN-OR官方发布的预编译二进制包:
- 下载预编译压缩包
!wget -q https://github.com/coin-or/Couenne/releases/download/releases%2F0.5.8/couenne-0.5.8-linux-x86_64.tar.gz
- 解压并赋予执行权限
!tar -xzf couenne-0.5.8-linux-x86_64.tar.gz !chmod +x couenne-0.5.8-linux-x86_64/bin/couenne
- 配置Pyomo识别求解器路径
import pyomo.environ as pyo couenne_exec_path = '/content/couenne-0.5.8-linux-x86_64/bin/couenne' solver = pyo.SolverFactory('couenne', executable=couenne_exec_path) print("Couenne求解器状态:", solver.available())
注:GitHub预编译包版本可能更新,若链接失效可前往COIN-OR官方仓库查找最新Linux版本。
内容的提问来源于stack exchange,提问作者N_Sh
相关产品推荐
相关产品推荐

