如何在MS Windows上安装CVXPY?

时间:2018-03-05 16:56:28

标签: python python-2.7 installation anaconda cvxpy

我正在尝试在Windows上安装CVXPY。我已经安装了Anaconda,所以我遵循this步骤。我将anaconda更新到最新版本,并检查我的计算机上是否安装了用于Python的Visual Studio C ++编译器。之后我从Anaconda安装SCS,运行建议的命令:

conda install -c https://conda.anaconda.org/omnia scs

这返回了一条错误消息:

Solving environment: failed

UnsatisfiableError: The following specifications were found to be in conflict:
    - blaze
    - scs
Use "conda info <package>" to see the dependencies for each package.

我不知道什么是火焰包,我想是由anaconda安装的东西,所以我从pip中取消了它然后安装了scs(我说这只是为了以防它重要,真正的问题现在来了)

安装SCS后我安装了CVXPY:

pip install cvxpy

显然在安装过程中没有出现错误信息,但后来我运行了测试:

nosetests cvxpy

这返回了27条错误消息,我不知道如何解决。 ¿其他人有这个问题,可以给我一些提示吗?

(我在这里粘贴了一些错误消息)。

======================================================================
ERROR: Failure: ImportError (cannot import name SymbolicQuadForm)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\nose\loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\nose\importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\nose\importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\reductions\__init__.py", line 25, in <module>
    from cvxpy.reductions.dcp2cone.cone_matrix_stuffing import ConeMatrixStuffing
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\reductions\dcp2cone\cone_matrix_stuffing.py", line 24, in <module>
    from cvxpy.reductions.matrix_stuffing import extract_mip_idx, MatrixStuffing
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\reductions\matrix_stuffing.py", line 25, in <module>
    from cvxpy.utilities.coeff_extractor import CoeffExtractor
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\utilities\coeff_extractor.py", line 31, in <module>
    from cvxpy.utilities.replace_quad_forms import replace_quad_forms
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\utilities\replace_quad_forms.py", line 20, in <module>
    from cvxpy.atoms.quad_form import SymbolicQuadForm, QuadForm
ImportError: cannot import name SymbolicQuadForm

======================================================================
ERROR: cvxpy.tests.test_constant_atoms.test_atom(<function <lambda> at 0x0000000008C444A8>, Problem(Maximize(Expression(CONCAVE, UNKNOWN, (1, 1))), []), -0.34481428, 'SCS')
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\tests\test_constant_atoms.py", line 295, in run_atom
    raise e
SolverError: Solver 'SCS' failed. Try another solver.
-------------------- >> begin captured stdout << ---------------------
FATAL: Cannot solve SDPs with > 2x2 matrices without linked blas+lapack libraries
Install blas+lapack and re-compile SCS with blas+lapack libray locations
ERROR: initCone failure
Failure:could not initialize work

--------------------- >> end captured stdout << ----------------------
======================================================================
ERROR: test_log_det (cvxpy.tests.test_examples.TestExamples)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\tests\test_examples.py", line 344, in test_log_det
    result = p.solve()
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\problems\problem.py", line 209, in solve
    return self._solve(*args, **kwargs)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\problems\problem.py", line 335, in _solve
    self._update_problem_state(results_dict, sym_data, solver)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\problems\problem.py", line 447, in _update_problem_state
    "Solver '%s' failed. Try another solver." % solver.name())
SolverError: Solver 'SCS' failed. Try another solver.
-------------------- >> begin captured stdout << ---------------------
FATAL: Cannot solve SDPs with > 2x2 matrices without linked blas+lapack libraries
Install blas+lapack and re-compile SCS with blas+lapack libray locations
ERROR: initCone failure
Failure:could not initialize work

--------------------- >> end captured stdout << ----------------------

======================================================================
ERROR: Test a problem with diag.
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\tests\test_problem.py", line 1379, in test_diag_prob
    result = prob.solve()
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\problems\problem.py", line 209, in solve
    return self._solve(*args, **kwargs)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\problems\problem.py", line 335, in _solve
    self._update_problem_state(results_dict, sym_data, solver)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\problems\problem.py", line 447, in _update_problem_state
    "Solver '%s' failed. Try another solver." % solver.name())
SolverError: Solver 'SCS' failed. Try another solver.
-------------------- >> begin captured stdout << ---------------------
FATAL: Cannot solve SDPs with > 2x2 matrices without linked blas+lapack libraries
Install blas+lapack and re-compile SCS with blas+lapack libray locations
ERROR: initCone failure
Failure:could not initialize work

--------------------- >> end captured stdout << ----------------------

======================================================================
ERROR: Test positive definite constraints.
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\tests\test_problem.py", line 1464, in test_psd_constraints
    result = prob.solve()
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\problems\problem.py", line 209, in solve
    return self._solve(*args, **kwargs)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\problems\problem.py", line 335, in _solve
    self._update_problem_state(results_dict, sym_data, solver)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\problems\problem.py", line 447, in _update_problem_state
    "Solver '%s' failed. Try another solver." % solver.name())
SolverError: Solver 'SCS' failed. Try another solver.
-------------------- >> begin captured stdout << ---------------------
FATAL: Cannot solve SDPs with > 2x2 matrices without linked blas+lapack libraries
Install blas+lapack and re-compile SCS with blas+lapack libray locations
ERROR: initCone failure
Failure:could not initialize work

--------------------- >> end captured stdout << ----------------------


======================================================================
ERROR: Failure: ImportError (cannot import name QuadForm)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\nose\loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\nose\importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\nose\importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\tests\test_qp.py", line 25, in <module>
    from cvxpy.atoms import (QuadForm, abs, power, quad_over_lin, sum, sum_squares, norm,
ImportError: cannot import name QuadForm

======================================================================
ERROR: Test sdp var.
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\tests\test_scs.py", line 85, in test_sdp_var
    prob.solve(verbose=True, solver=SCS)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\problems\problem.py", line 209, in solve
    return self._solve(*args, **kwargs)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\problems\problem.py", line 335, in _solve
    self._update_problem_state(results_dict, sym_data, solver)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\problems\problem.py", line 447, in _update_problem_state
    "Solver '%s' failed. Try another solver." % solver.name())
SolverError: Solver 'SCS' failed. Try another solver.
-------------------- >> begin captured stdout << ---------------------
----------------------------------------------------------------------------
        SCS v1.2.6 - Splitting Conic Solver
        (c) Brendan O'Donoghue, Stanford University, 2012-2016
----------------------------------------------------------------------------
Lin-sys: sparse-indirect, nnz in A = 15, CG tol ~ 1/iter^(2.00)
eps = 1.00e-03, alpha = 1.50, max_iters = 2500, normalize = 1, scale = 1.00
Variables n = 6, constraints m = 15
Cones:  primal zero / dual free vars: 9
        sd vars: 6, sd blks: 1
FATAL: Cannot solve SDPs with > 2x2 matrices without linked blas+lapack libraries
Install blas+lapack and re-compile SCS with blas+lapack libray locations
ERROR: initCone failure
Setup time: 2.45e-04s
Failure:could not initialize work

--------------------- >> end captured stdout << ----------------------

======================================================================
ERROR: Test sigma_max.
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\tests\test_scs.py", line 75, in test_sigma_max
    result = prob.solve(solver=SCS)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\problems\problem.py", line 209, in solve
    return self._solve(*args, **kwargs)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\problems\problem.py", line 335, in _solve
    self._update_problem_state(results_dict, sym_data, solver)
File "C:\Users\alvaromc317\Anaconda2\lib\site-packages\cvxpy\problems\problem.py", line 447, in _update_problem_state
    "Solver '%s' failed. Try another solver." % solver.name())
SolverError: Solver 'SCS' failed. Try another solver.
-------------------- >> begin captured stdout << ---------------------
FATAL: Cannot solve SDPs with > 2x2 matrices without linked blas+lapack libraries
Install blas+lapack and re-compile SCS with blas+lapack libray locations
ERROR: initCone failure
Failure:could not initialize work

--------------------- >> end captured stdout << ----------------------

----------------------------------------------------------------------
Ran 1775 tests in 14.630s

FAILED (errors=27)

3 个答案:

答案 0 :(得分:2)

@sacha是对的。您必须从源或通过cvxgrp conda通道安装SCS。 omn​​ia版本的SCS不完整。但是您的安装足以解决许多问题,而不是SDP。如果您安装MOSEK,您可以完全忘记SCS。

答案 1 :(得分:0)

我遇到与您类似的错误。到目前为止,这是我尝试过的。 根据他们的网站:

conda install -c conda-forge lapack
conda install -c cvxgrp cvxpy

,在这两个版本之前,我将安装它:

conda install -c cvxgrp scs

@steven:我尝试安装MOSEK,它使“ nosetests cvxpy”出现了很多错误,以致于它崩溃了。

答案 2 :(得分:0)

这是我为 Python 3.7 安装 CVXPY 所做的操作

第 1 步:

转到https://www.lfd.uci.edu/~gohlke/pythonlibs/#scs 并下载以下文件(您需要选择与您的机器和 Python 版本匹配的文件,2.0.7 号将来可能会更新)。我的是:

ecos-2.0.7.post1-cp37-cp37m-win_amd64.whl
scs-2.1.3-cp37-cp37m-win_amd64.whl
cvxpy-1.1.12-cp37-cp37m-win_amd64.whl

第 2 步:

进入你的Anaconda目录,比如我的在C:\users\zyoung\Anaconda3,找到一个名为pkgs的文件夹,比如我的是C:\users\zyoung\Anaconda3\pkgs,把第一步中的3个文件保存在这个文件夹。

第 3 步:

cmd 打开您的 Anaconda Prompt 并转到步骤 2 中的文件夹并输入以下命令

C:\users\zyoung\Anaconda3>cd pkgs
C:\users\zyoung\Anaconda3\pkgs> pip install ecos-2.0.7.post1-cp37-cp37m-win_amd64.whl

安装成功后,输入

pip install scs-2.1.3-cp37-cp37m-win_amd64.whl

安装成功后,输入

pip install cvxpy-1.1.12-cp37-cp37m-win_amd64.whl

当这成功时,你就完成了!