我按照以下步骤操作,遇到了第一个错误:
<code>wget http://www.dcc.fc.up.pt/~jpp/code/python-glpk/python-glpk_0.4.43.orig.tar.gz tar -xzf python-glpk_0.4.43.orig.tar.gz cd python-glpk-0.4.43/src/ sudo make install </code>
我收到此错误:
<code>make -C swig all
make[1]: pyversions: Command not found
gcc -Wall -c -fPIC glpkpi_wrap.c -DHAVE_CONFIG_H -I/usr/include/ -I/usr/lib//config
glpkpi_wrap.c:130:11: fatal error: 'Python.h' file not found
# include <Python.h>
^
1 error generated.
make[1]: *** [glpkpi_wrap.o] Error 1
make: *** [all] Error 2
</code>
然后我通过更改Python版本或下面的部分链接到python:
在swig / Makefile中
变了
<code>PYVERS := $(shell pyversions -d) </code>
至
<code>PYVERS := "Python 2.7.6" </code>
这是我的python版本
<code>make -C swig all swig -python glpkpi.i ./glpk.h:916: Warning 314: 'in' is a python keyword, renaming to '_in' sed -i 's/:in /:_in /g' glpkpi.py sed: 1: "glpkpi.py": extra characters at the end of g command make[1]: *** [glpkpi.py] Error 1 make: *** [all] Error 2 </code>
现在,当我在示例文件夹中运行python test.py时,它只是崩溃并说:
<code>Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/glpk/__init__.py", line 26, in <module>
from glpk_parser import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/glpk/glpk_parser.py", line 352, in <module>
yacc.yacc(write_tables=0, debug=0)
File "/Library/Python/2.7/site-packages/ply/yacc.py", line 3244, in yacc
read_signature = lr.read_table(tabmodule)
File "/Library/Python/2.7/site-packages/ply/yacc.py", line 1967, in read_table
if parsetab._tabversion != __tabversion__:
AttributeError: 'module' object has no attribute '_tabversion'
</code>
我尝试了以下教程:
Build and install from source
然后我尝试
Installing-Python-glpk Tutorial
只是不对,我错过了哪一步导致
<code>import glpk </code>
失败?
我也尝试了Brew安装,没有运气!我也包括了我的Python路径,仍然没有帮助.
啊,最后我尝试了这个:
<code>import sys
sys.path.append('/Library/Python/2.7/site-packages/glpk/')
</code>
还是没有运气!最后一步是来自这个answer的灵感
解决方法:
好的,我尝试重现您的问题,并遇到了相同的错误,
我设法通过将层板的版本从3.6更改为3.4使其起作用.
请注意,我的glpk库出现错误,必须将其降级为4.43
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!