NAME

python-config – output build options for python C/C++ extensions or embedding  

SYNOPSIS

python-config [ –prefix ] [ –exec-prefix ] [ –includes ] [ –libs ] [ –cflags ] [ –ldflags ] [ –extension-suffix ] [ –configdir ] [ –help ]  

DESCRIPTION

python-config helps compiling and linking programs, which embed the Python interpreter, or extension modules that can be loaded dynamically (at run time) into the interpreter.  

OPTIONS

–cflags
print the C compiler flags.
–ldflags
print the flags that should be passed to the linker.
–includes
similar to –cflags but only with -I options (path to python header files).
–libs
similar to –ldflags but only with -l options (used libraries).
–prefix
prints the prefix (base directory) under which python can be found.
–exec-prefix
print the prefix used for executable program directories (such as bin, sbin, etc).
–extension-suffix
print suffix used for extension modules (including the _d modified for debug builds).
–configdir
prints the path to the configuration directory under which the Makefile, etc. can be found).
–help
print the usage message.

 

EXAMPLES

To build the singe-file c program prog against the python library, use

gcc $(python-config –cflags –ldflags) progr.cpp -o progr.cpp

The same in a makefile:

CFLAGS+=$(shell python-config –cflags)
LDFLAGS+=$(shell python-config –ldflags)
all: progr

To build a dynamically loadable python module, use

gcc $(python-config –cflags –ldflags) -shared -fPIC progr.cpp -o progr.so

 

Willie has over 15 years of experience in Linux system administration and DevOps. After managing infrastructure for startups and enterprises alike, he founded Command Linux to share the practical knowledge he wished he had when starting out. He oversees content strategy and contributes guides on server management, automation, and security.