How to determine the path & name of the Python shared library?

I'm not sure how or if it can be done within Python itself, but you can use standard tools for finding shared library dependencies for the python executable.

Linux: ldd <path>/python or ldd $(which python)
Mac: otool -L <path>/python
Windows: run dependencywalker on python.exe


With pure Python tested on Amazon Linux after a sudo yum install python3

import sysconfig
sysconfig.get_config_vars('LIBDIR', 'INSTSONAME')  
# -> ['/usr/lib64', 'libpython3.7m.so.1.0']

Edit: Note that some distributions (i.e Linux and Python >= 3.8) will not contain a shared library anymore, but will link statically to libpython3.8.a.

Tags:

Python