Python Distutils与shell扩展
我有一个Python扩展模块,它需要GTK。编译GTK程序通常需要大量的链接,因为GTK依赖于许多其他库(Glib、Cairo、Pango等)。因此,通常我只是使用shell扩展(back ticks)使用Python Distutils与shell扩展,python,bash,distutils,Python,Bash,Distutils,我有一个Python扩展模块,它需要GTK。编译GTK程序通常需要大量的链接,因为GTK依赖于许多其他库(Glib、Cairo、Pango等)。因此,通常我只是使用shell扩展(back ticks)使用pkg config的输出进行编译,如: 但出于某种原因,当我在传递给distutils中的模块.extra\u compile\u args的参数中使用shell扩展时,我会得到一个错误,因为BASH实际上没有扩展表达式: module = Extension('mymodule',
pkg config
的输出进行编译,如:
但出于某种原因,当我在传递给distutils中的模块.extra\u compile\u args
的参数中使用shell扩展时,我会得到一个错误,因为BASH实际上没有扩展表达式:
module = Extension('mymodule',
sources = ['mymodule.c'])
module.extra_compile_args = ['`pkg-config --cflags gtk+-3.0`',
'`pkg-config --libs gtk+-3.0`'];
这只会导致如下错误:
gcc: error: `pkg-config --cflags gtk+-3.0`: No such file or directory
那么,有什么办法可以让这一切顺利进行吗?我是否需要手动执行shell扩展,将pkg config
的输出作为Python字符串获取,然后将其作为元素添加到module.extra\u compile\u args
module.extra_compile_args = [
subprocess.check_output(["pkg-config", "--cflags", "gtk+-3.0"]),
subprocess.check_output(["pkg-config", "--libs", "gtk+-3.0"])
];
module.extra_compile_args = [
subprocess.check_output(["pkg-config", "--cflags", "gtk+-3.0"]),
subprocess.check_output(["pkg-config", "--libs", "gtk+-3.0"])
];