Python:为什么在MacOSX上导入glpk时会遇到此错误?
作者:互联网
我按照以下步骤操作,遇到了第一个错误:
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
我收到此错误:
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
然后我通过更改Python版本或下面的部分链接到python:
在swig / Makefile中
变了
PYVERS := $(shell pyversions -d)
至
PYVERS := "Python 2.7.6"
这是我的python版本
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
现在,当我在示例文件夹中运行python test.py时,它只是崩溃并说:
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'
我尝试了以下教程:
Build and install from source
然后我尝试
Installing-Python-glpk Tutorial
只是不对,我错过了哪一步导致
import glpk
失败?
我也尝试了Brew安装,没有运气!我也包括了我的Python路径,仍然没有帮助.
啊,最后我尝试了这个:
import sys
sys.path.append('/Library/Python/2.7/site-packages/glpk/')
还是没有运气!最后一步是来自这个answer的灵感
解决方法:
好的,我尝试重现您的问题,并遇到了相同的错误,
我设法通过将层板的版本从3.6更改为3.4使其起作用.
请注意,我的glpk库出现错误,必须将其降级为4.43
标签:python-2-7,compiler-errors,glpk,python 来源: https://codeday.me/bug/20191028/1949356.html