title: Python: Why am I encountering this error with importing glpk on MacOSX?
body: <p>I followed these steps and got my first error:</p>
  
  <pre><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></pre>
  
  <p>I got this error:</p>
  
  <pre><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 &lt;Python.h&gt;
            ^
  1 error generated.
  make[1]: *** [glpkpi_wrap.o] Error 1
  make: *** [all] Error 2
  </code></pre>
  
  <p>Then I linked to the python by changing the Python version or let's say section:
  inside <code>swig/Makefile</code></p>
  
  <p>changed </p>
  
  <pre><code>PYVERS := $(shell pyversions -d)
  </code></pre>
  
  <p>to</p>
  
  <pre><code>PYVERS := "Python 2.7.6" 
  </code></pre>
  
  <p>which is my python version</p>
  
  <pre><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></pre>
  
  <p>Now when I run <code>python test.py</code> inside the examples folder, it just crashes and says:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/glpk/__init__.py", line 26, in &lt;module&gt;
      from glpk_parser import *
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/glpk/glpk_parser.py", line 352, in &lt;module&gt;
      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></pre>
  
  <p>I tried the following tutorials:
  <a href="https://en.wikibooks.org/wiki/GLPK/Python" rel="nofollow noreferrer">Build and install from source</a></p>
  
  <p>then I tried</p>
  
  <p><a href="http://blog.ducky.io/python/2013/07/01/Installing-Python-glpk/" rel="nofollow noreferrer">Installing-Python-glpk Tutorial</a></p>
  
  <p>Something is just not right, what step am I missing that is causing the </p>
  
  <pre><code>import glpk
  </code></pre>
  
  <p>to fail?</p>
  
  <p>I tried brew installation as well, no luck! I have included my Python path as well, still no help.</p>
  
  <p>Ah and lastly I tried this:</p>
  
  <pre><code>import sys    
  
  sys.path.append('/Library/Python/2.7/site-packages/glpk/')
  </code></pre>
  
  <p>still no luck! Last step was inspiration from this <a href="https://stackoverflow.com/a/5564891/539075">answer</a></p>