【问题标题】:Setting up Gurobi with Python使用 Python 设置 Gurobi
【发布时间】:2020-08-17 05:19:35
【问题描述】:

我正在尝试在Python 中使用Gurobi。作为 IDE,我使用PyCharm。当我使用通过PyCharm 安装gurobipy 时,我收到以下错误。

我还尝试通过Anaconda 安装库,如this link 所示。但是,我收到如下所示的另一个错误。

(base) C:\Users\...>conda install -c gurobi gurobi
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: -
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - gurobi -> python[version='2.7.*|3.5.*|>=2.7,<2.8.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|3.4.*']

Your python: python=3.8

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

The following specifications were found to be incompatible with your CUDA driver:

  - feature:/win-64::__cuda==11.0=0
  - feature:|@/win-64::__cuda==11.0=0

Your installed CUDA driver is: 11.0

我有Gurobi 9.0.2 的学术版本,并在Windows 10 中使用Python 3.8.3。我想知道如何解决这个问题。

【问题讨论】:

    标签: python gurobi


    【解决方案1】:

    我无法发表评论,但您使用的 python 版本似乎与 gurobipy 库/包不兼容。您可能希望使用 Python 3.7 创建一个新的 conda 环境,并尝试将 gurobipy 库下载到该 conda 环境中。这是执行此操作的参考https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

    【讨论】:

    • 我按照你的建议做了。我使用 python 3.7 创建了一个环境并通过它安装了 gurobi。我的问题是我现在将如何在我的项目中使用它。
    • 我很高兴听到它奏效了。您可以通过在终端会话中调用(此处假设环境名为 py_env):“conda activate py_env”来“使用”环境。如果您使用的是 IDE,例如 VS Code 或 PyCharm,我无法在不知道类型的情况下给出具体建议,但通常它们允许您在选择使用的 python 版本时选择环境。
    • 在 PyCharm 中,我进入终端会话并首先调用 conda create -n myenv gurobi。我可以看到gurobi 被下载为库。然后,我按照您的建议调用conda activate myenv。但是,我仍然无法使用该库。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-13
    • 1970-01-01
    • 1970-01-01
    • 2022-07-25
    • 1970-01-01
    • 2021-01-22
    相关资源
    最近更新 更多