You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyPSA-EUR配置HiGHS求解器报错,如何正确配置使用?

解决PyPSA-EUR中HiGHS求解器的配置问题

问题描述

在PyPSA-EUR的config.yaml中配置HiGHS求解器:

solver:
    name: highs
    options: {}

运行时触发以下错误:

RuntimeError: Attempting to use an unavailable solver.

The SolverFactory was unable to create the solver "highs" and returned
an UnknownSolver object. This error is raised at the point where the
UnknownSolver object was used as if it were valid (by calling method
"has_capability").

The original solver was created with the following parameters:
executable: highs
type: highs
_args: ()
options: {}

已确认环境中highspy安装正常,执行python -c "import highspy"无报错。

解决方案

  1. 验证Pyomo对HiGHS的兼容性
    PyPSA依赖Pyomo调用求解器,确保Pyomo版本≥6.4.0(此版本开始完善对HiGHS的支持)。检查当前版本:

    pip show pyomo
    

    版本过低则升级:

    pip install --upgrade pyomo
    
  2. 调整config.yaml的求解器配置
    尝试两种配置方式:

    • 若使用命令行版HiGHS,明确指定可执行文件路径(若系统PATH中未包含):
      solver:
        name: highs
        options: {}
        executable: "/path/to/your/highs/executable"  # 替换为实际路径,比如~/envs/pypsa-eur/bin/highs
      
    • 若使用highspy的Python接口,改用highs_python作为求解器名称:
      solver:
        name: highs_python
        options: {}
      
  3. 测试Pyomo能否调用HiGHS
    在环境中运行以下代码验证:

    from pyomo.environ import SolverFactory
    solver = SolverFactory("highs")  # 或对应highs_python
    print(solver.available())
    print(solver.has_capability("linear"))
    

    若输出均为True,说明Pyomo已能正常识别HiGHS,重启PyPSA-EUR流程即可。

  4. 确保HiGHS可执行文件在PATH中
    执行highs --version验证命令行版HiGHS是否可调用,若提示命令不存在,需将HiGHS的安装目录添加到系统PATH,或在config.yaml中指定绝对路径。

内容的提问来源于stack exchange,提问作者Dakait

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 00:52:56