Python 在Anaconda上安装CPLEX

Python 在Anaconda上安装CPLEX,python,anaconda,cplex,pulp,Python,Anaconda,Cplex,Pulp,正在尝试安装CPLEX以用于优化。情况就是这样: conda install -c ibmdecisionoptimization cplex Collecting package metadata (current_repodata.json): done Solving environment: failed with initial frozen solve. Retrying with flexible solve. Solving environment: failed with re

正在尝试安装CPLEX以用于优化。情况就是这样:

conda install -c ibmdecisionoptimization cplex
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:

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

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.

最简单的解决方案是创建一个新的虚拟环境。在这种情况下,要指定python版本,可以在condacreate命令中传递包版本。例如,如果希望使用python 3.6创建一个名为env_w_python36的新环境,请运行以下命令:

conda create-n env_w_python36 python=3.6
然后,您可以检查您的环境中是否安装了正确的python版本:

$conda激活环境水蟒36
(env_w_python36)$python——版本
Python 3.6.12::Anaconda公司。

另一种解决方案可能是通过请求特定版本来降级/升级当前环境中的python版本:

conda安装python=3.6

请注意,它可能会与已安装的软件包产生大量冲突。每当您想使用不同版本的python时,创建一个新的环境几乎总是一条捷径。

对于第二个问题,请选中
pill。CPLEX_CMD()
不需要CPLEX库,只需要CPLEX可执行路径。如果您想通过<代码> CPLEX < /代码> Python包使用CPLEX,您可以使用<代码> Pr.Cople()/代码>建议:考虑从答案中省略<代码> CONDA安装Python=3.6 < /Cord>选项。每当需要不同的Python版本时,创建新环境几乎总是正确的选择。
import pulp
import cplex
prob.solve(pulp.CPLEX_CMD())