Python: Why am I facing this error when importing glpk on MacOSX?

I followed the steps below and got the first error:

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

      

I got this error:

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

      

Then I contacted python by changing the Python version or let's say the section: inside swig/Makefile

changed

PYVERS := $(shell pyversions -d)

      

to

PYVERS := "Python 2.7.6" 

      

which is my python version

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

      

Now when I run python test.py

inside the examples folder it just crashes and says:

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'

      

I tried the following tutorials: Build and Install from Source

then i tried

Install-python-glpk Tutorial

Something is just wrong, which step I am missing, which is causing

import glpk

      

crash?

I tried brew install, no luck! I also included my Python path, still not helping.

Ah, and finally I tried this:

import sys    

sys.path.append('/Library/Python/2.7/site-packages/glpk/')

      

still no luck! The last step was the inspiration in this answer

+3


source to share


1 answer


Ok I tried to reproduce your problem and went through the same errors, I managed to get it to work by changing the version ply

from 3.6 to 3.4.



Please note that I had a bug with the library glpk

and had to downgrade it to 4.43

+3


source







All Articles