我想使用 CyLP 包(https://github.com/coin-or/CyLP)。我的操作系统是 macOS Big Sur 11.5.1。我正在通过 anaconda3 使用 Python 3.8.8。按照自述文件中的说明,我首先通过自制软件安装了 cbc。由于它无法与brew install coin-or-tools/coinor/cbc
我使用brew install cbc
. 然后我通过pip install cylp
.
安装成功。CyLP 安装在目录中/opt/homebrew/anaconda3/lib/python3.8/site-packages/cylp
。但是,现在如果我尝试python -m unittest discover
CyLP 目录中的单元测试,它会给我下面附加的错误。
提到的文件在目录中,所以我不知道如何解决这个问题。有谁能够帮我?
ERROR: cy (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: cy
Traceback (most recent call last):
File "/opt/homebrew/anaconda3/lib/python3.8/unittest/loader.py", line 470, in _find_test_path
package = self._get_module_from_name(name)
File "/opt/homebrew/anaconda3/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
__import__(name)
File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/cylp/cy/__init__.py", line 1, in <module>
from .CyCoinIndexedVector import CyCoinIndexedVector
ImportError: dlopen(/opt/homebrew/anaconda3/lib/python3.8/site-packages/cylp/cy/CyCoinIndexedVector.cpython-38-darwin.so, 2): Symbol not found: __ZN9CoinError12printErrors_E
Referenced from: /opt/homebrew/anaconda3/lib/python3.8/site-packages/cylp/cy/CyCoinIndexedVector.cpython-38-darwin.so
Expected in: flat namespace
in /opt/homebrew/anaconda3/lib/python3.8/site-packages/cylp/cy/CyCoinIndexedVector.cpython-38-darwin.so
======================================================================
ERROR: py (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: py
Traceback (most recent call last):
File "/opt/homebrew/anaconda3/lib/python3.8/unittest/loader.py", line 470, in _find_test_path
package = self._get_module_from_name(name)
File "/opt/homebrew/anaconda3/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
__import__(name)
File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/cylp/py/__init__.py", line 1, in <module>
from . import pivots
File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/cylp/py/pivots/__init__.py", line 3, in <module>
from .PositiveEdgePivot import PositiveEdgePivot
File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/cylp/py/pivots/PositiveEdgePivot.py", line 9, in <module>
from cylp.cy import CyCoinIndexedVector
File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/cylp/cy/__init__.py", line 1, in <module>
from .CyCoinIndexedVector import CyCoinIndexedVector
ImportError: dlopen(/opt/homebrew/anaconda3/lib/python3.8/site-packages/cylp/cy/CyCoinIndexedVector.cpython-38-darwin.so, 2): Symbol not found: __ZN9CoinError12printErrors_E
Referenced from: /opt/homebrew/anaconda3/lib/python3.8/site-packages/cylp/cy/CyCoinIndexedVector.cpython-38-darwin.so
Expected in: flat namespace
in /opt/homebrew/anaconda3/lib/python3.8/site-packages/cylp/cy/CyCoinIndexedVector.cpython-38-darwin.so
----------------------------------------------------------------------
Ran 2 tests in 0.000s
更新 12.09.21 它仍然不起作用,但我取得了进展。
首先,我尝试正确安装 CBC。我认识到了这个问题,所以我从源代码安装了 CBC 及其所有依赖项。完成后,我仍然无法使用pip install cylp
. 即使设置COIN_INSTALL_DIR
到我的安装目录后,它也显示与我的架构相关的错误,x86 是什么。我意识到我一直在尝试 anaconda 3.8 上的所有内容,所以我改用 python 3.9。接下来,我克隆了 cylp 的存储库并使用pip3 install
.
现在它显示了我的架构并且不再忽略.dylib
文件。但现在我得到这个错误:
cylp/cpp/ICbcModel.cpp:35:9: error: no matching function for call to 'CbcMain0'
CbcMain0(*this);
^~~~~~~~
/Users/usr1/dist/include/coin/CbcSolver.hpp:310:6: note: candidate function not viable: requires 2 arguments, but 1 was provided
void CbcMain0(CbcModel &babSolver, CbcSolverUsefulData &solverData);
^
cylp/cpp/ICbcModel.cpp:37:16: error: no matching function for call to 'CbcMain1'
return CbcMain1(3, argv, *this);
^~~~~~~~
/Users/usr1/dist/include/coin/CbcSolver.hpp:314:5: note: candidate function not viable: requires 4 arguments, but 3 were provided
int CbcMain1(int argc, const char *argv[], CbcModel &babSolver,
^
/Users/usr1/dist/include/coin/CbcSolver.hpp:312:5: note: candidate function not viable: requires 5 arguments, but 3 were provided
int CbcMain1(int argc, const char *argv[], CbcModel &babSolver, int(CbcModel *currentSolver, int whereFrom), CbcSolverUsefulData &solverData);
^
2 errors generated.
error: command '/usr/bin/clang' failed with exit code 1
----------------------------------------
ERROR: Failed building wheel for cylp........
第二次更新 12.09.21
我想我解决了这个问题。
我仍然收到此错误:
m.addConstraint(A * x == b)
EEClp6001E Unable to open file /opt/homebrew/lib/python3.9/site-packages/cylp/py/modeling/../../input/p0033.mps for reading
Clp3002W Empty problem - 0 rows, 3 columns and 0 elements
Clp0000I Optimal - objective value 0
E.Clp6001E Unable to open file /opt/homebrew/lib/python3.9/site-packages/cylp/py/../input/netlib/adlittle.mps for reading
zsh: segmentation fault python3 -m unittest discover
但是第一个可能是可以忽略的,第二个只是GitHub Repository中不存在两个文件的产物。
所以我尝试编写自己的示例代码,到目前为止一切正常。
在修复发生的错误的最后一步中,我插入ICbcModel.cpp
了CbcSolverUsefulData
to give toCbcMain0
和CbcMain1
.
我希望如果有人有同样的问题,这篇文章会帮助他们。