Distribution independent libpython path
Question: Under newer Ubuntu/Debian versions, `libpython2.7.so` is under
`/usr/lib/i386-linux-gnu/libpython2.7.so` or `/usr/lib/x86_64-linux-
gnu/libpython2.7.so`, etc. Earlier, they could be found in
`/usr/lib/libpython2.7.so`, no matter the architecture. I haven't checked for
other distributions. How do I find the path of `libpython2.7.so` with python?


Answer: Using `pkg-config` is not the best option - it will not distinguish between
different installations of Python, returning only the system installation. You
are better off using the Python executable to discover the location of
`libpythonX.Y.so`.

From inside Python:

    
    
       from distutils import sysconfig;
       print sysconfig.get_config_var("LIBDIR")
    

Or inside a Makefile:

    
    
       PYTHON_LIBDIR:=$(shell python -c 'from distutils import sysconfig; print sysconfig.get_config_var("LIBDIR")')
    

This will discover the location from whatever Python executable is first in
`$PATH` and thus will work if there are multiple Python installations on the
system.

Credit to [Niall
Fitzgerald](https://github.com/potentialventures/cocotb/issues/128) for
pointing this out.

