在较新的 Ubuntu/Debian 版本下,libpython2.7.so
位于 /usr/lib/i386-linux-gnu/libpython2.7.so
或 /usr/lib/x86_64-linux-gnu/libpython2.7.so
等,早前可以在/usr/lib/libpython2.7.so
中找到,没有重要的架构。我还没有检查其他发行版。 python如何找到libpython2.7.so
的路径?
最佳答案
使用 pkg-config
不是最好的选择——它不会区分不同的 Python 安装,只返回系统安装。您最好使用 Python 可执行文件来发现 libpythonX.Y.so
的位置。
从 Python 内部:
from distutils import sysconfig;
print sysconfig.get_config_var("LIBDIR")
或者在 Makefile 中:
PYTHON_LIBDIR:=$(shell python -c 'from distutils import sysconfig; print sysconfig.get_config_var("LIBDIR")')
这将从 $PATH
中最先出现的任何 Python 可执行文件中发现位置,因此如果系统上安装了多个 Python,它也能正常工作。
归功于 Niall Fitzgerald感谢您指出这一点。
关于python - 分发独立的 libpython 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20582270/