我在Mac OS X El Capitan上。
我通过brew install GLPK
安装了GLPK
我通过Anaconda安装了python。
因为我想要CVXOPT的GLPK绑定,我手动而不是通过condo install
安装它。
我在这里找到了安装程序:http://cvxopt.org/download/index.html
一旦我得到了安装程序,我就按照本页上的说明操作:
http://lecueguillaume.github.io/2016/02/27/cvxopt-glpk-basis-pursuit/
修改setup.py文件。
我做了一些额外的改动。首先,我注释掉了环境变量,以便排除它拾取它们的可能性,而不是我放入文件中的变量:
#BUILD_GLPK = int(os.environ.get("CVXOPT_BUILD_GLPK",BUILD_GLPK))
#GLPK_LIB_DIR = os.environ.get("CVXOPT_GLPK_LIB_DIR",GLPK_LIB_DIR)
#GLPK_INC_DIR = os.environ.get("CVXOPT_GLPK_INC_DIR",GLPK_INC_DIR)
接下来我设置了这些变量:
BUILD_GLPK = 1
libglpk
的目录(仅在BUILD_GLPK = 1
时使用)。
GLPK_LIB_DIR = '/usr/local/Cellar/glpk/4.57/lib'
glpk.h
的目录(仅在BUILD_GLPK = 1
时使用)。
GLPK_INC_DIR = '/usr/local/Cellar/glpk/4.57/include'
我的brew安装给了我gulp 4.57而不是教程中的那个,所以我在上面修改了那些版本号。
最后,为了确保它正在运行,我添加了这个:
if BUILD_GLPK:
print "*** BUILDING GLPK ***"
if BUILD_GLPK
已经存在,我添加了打印行。
然后我开始跑python setup.py install
看起来很棒:
*** BUILDING GLPK ***
running install
running bdist_egg
running egg_info
writing cvxopt.egg-info/PKG-INFO
writing top-level names to cvxopt.egg-info/top_level.txt
writing dependency_links to cvxopt.egg-info/dependency_links.txt
reading manifest file 'cvxopt.egg-info/SOURCES.txt'
writing manifest file 'cvxopt.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.6-x86_64/egg
running install_lib
running build_py
running build_ext
sh: line 1: 91286 Segmentation fault: 11 'gcc' --version 2> /dev/null > '/tmp/tmp1Xzj0m'
creating build/bdist.macosx-10.6-x86_64/egg
creating build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/__init__.py -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/amd.so -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/base.so -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/blas.so -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/cholmod.so -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/coneprog.py -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/cvxprog.py -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/glpk.so -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/info.py -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/lapack.so -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/misc.py -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/misc_solvers.so -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/modeling.py -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/msk.py -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/printing.py -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/solvers.py -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
copying build/lib.macosx-10.6-x86_64-2.7/cvxopt/umfpack.so -> build/bdist.macosx-10.6-x86_64/egg/cvxopt
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/__init__.py to __init__.pyc
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/coneprog.py to coneprog.pyc
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/cvxprog.py to cvxprog.pyc
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/info.py to info.pyc
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/misc.py to misc.pyc
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/modeling.py to modeling.pyc
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/msk.py to msk.pyc
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/printing.py to printing.pyc
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/solvers.py to solvers.pyc
creating stub loader for cvxopt/glpk.so
creating stub loader for cvxopt/base.so
creating stub loader for cvxopt/blas.so
creating stub loader for cvxopt/lapack.so
creating stub loader for cvxopt/umfpack.so
creating stub loader for cvxopt/cholmod.so
creating stub loader for cvxopt/amd.so
creating stub loader for cvxopt/misc_solvers.so
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/glpk.py to glpk.pyc
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/base.py to base.pyc
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/blas.py to blas.pyc
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/lapack.py to lapack.pyc
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/umfpack.py to umfpack.pyc
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/cholmod.py to cholmod.pyc
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/amd.py to amd.pyc
byte-compiling build/bdist.macosx-10.6-x86_64/egg/cvxopt/misc_solvers.py to misc_solvers.pyc
creating build/bdist.macosx-10.6-x86_64/egg/EGG-INFO
copying cvxopt.egg-info/PKG-INFO -> build/bdist.macosx-10.6-x86_64/egg/EGG-INFO
copying cvxopt.egg-info/SOURCES.txt -> build/bdist.macosx-10.6-x86_64/egg/EGG-INFO
copying cvxopt.egg-info/dependency_links.txt -> build/bdist.macosx-10.6-x86_64/egg/EGG-INFO
copying cvxopt.egg-info/top_level.txt -> build/bdist.macosx-10.6-x86_64/egg/EGG-INFO
writing build/bdist.macosx-10.6-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating 'dist/cvxopt-1.1.8-py2.7-macosx-10.6-x86_64.egg' and adding 'build/bdist.macosx-10.6-x86_64/egg' to it
removing 'build/bdist.macosx-10.6-x86_64/egg' (and everything under it)
Processing cvxopt-1.1.8-py2.7-macosx-10.6-x86_64.egg
Copying cvxopt-1.1.8-py2.7-macosx-10.6-x86_64.egg to /Users/myUsername/anaconda/lib/python2.7/site-packages
Adding cvxopt 1.1.8 to easy-install.pth file
然而,当我在python中运行它时:
/Users/myUsername/anaconda/lib/python2.7/site-packages/cvxopt-1.1.8-py2.7-macosx-10.6-x86_64.egg/cvxopt/coneprog.pyc in lp(c, G, h, A, b, solver, primalstart, dualstart, **kwargs)
2805 if solver == 'glpk':
2806 try: from cvxopt import glpk
-> 2807 except ImportError: raise ValueError("invalid option "\
2808 "(solver = 'glpk'): cvxopt.glpk is not installed")
2809 glpk.options = options.get('glpk',{})
ValueError: invalid option (solver = 'glpk'): cvxopt.glpk is not installed
我尝试过卸载并重新安装几种不同的方法。这个似乎是最有希望的,但我仍然没有运气。有什么建议吗?