fedora /usr/lib 与 /usr/lib64

Wei*_*wei 4 python fedora libraries

看来我有两个 python2.6 文件夹分别位于 /usr/lib 和 /usr/lib64 中。大多数 python 的东西(源代码)在 /usr/lib64/python2.6 中,但是当在安装的包中时,它们已被放入 /usr/lib/python2.6

当python被请求时系统如何决定去哪个目录,以及它如何找到我安装的包?

小智 7

这个简单的答案是,在没有任何 C/native 扩展的情况下构建的包应该在 lib 下结束,任何带有本机扩展的包都将在 multilib 系统上以 lib64 结束。至于它如何找到包含在 sys.path 中的包 - 这是来自 x86_64 F-11 系统:

>>> import sys
>>> for pth in sys.path: print pth
... 

/usr/lib64/python26.zip
/usr/lib64/python2.6
/usr/lib64/python2.6/plat-linux2
/usr/lib64/python2.6/lib-tk
/usr/lib64/python2.6/lib-old
/usr/lib64/python2.6/lib-dynload
/usr/lib64/python2.6/site-packages
/usr/lib64/python2.6/site-packages/Numeric
/usr/lib64/python2.6/site-packages/gst-0.10
/usr/lib64/python2.6/site-packages/gtk-2.0
/usr/lib/python2.6/site-packages
Run Code Online (Sandbox Code Playgroud)

关于包如何到达那里的更详细的答案需要对 python 在它自己的布局方面的工作方式有一些了解。我们感兴趣的是名为distutils的标准库的一部分。这是主力,请注意,在此基础上还构建了一些工具(setuptools)和一个名为distribute的分支,目前正在尝试改进python打包。

有一个 Fedora 适用的重要补丁在这里谈论它使所有这些工作:

在 lib 目录为 lib64 的体系结构上,此补丁有条件地应用于Python的 RPM规范中:

如果我们看看它是如何修补 distutils 的:

diff -up Python-2.6/Lib/distutils/sysconfig.py.lib64 Python-2.6/Lib/distutils/sysconfig.py
--- Python-2.6/Lib/distutils/sysconfig.py.lib64 2008-06-05 08:58:24.000000000 -0400
+++ Python-2.6/Lib/distutils/sysconfig.py   2008-11-24 02:34:04.000000000 -0500
@@ -115,8 +115,12 @@ def get_python_lib(plat_specific=0, stan
         prefix = plat_specific and EXEC_PREFIX or PREFIX

     if os.name == "posix":
+        if plat_specific or standard_lib:
+            lib = "lib64"
+        else:
+            lib = "lib"
         libpython = os.path.join(prefix,
-                                 "lib", "python" + get_python_version())
+                                 lib, "python" + get_python_version())
         if standard_lib:
             return libpython
         else:
Run Code Online (Sandbox Code Playgroud)

我们现在在 distutils 上有一个条件,distutils.sysconfig.get_python_lib()当我们询问平台特定或系统包时,它现在改变了返回的内容。您可以尝试在 python 解释器中使用各种选项调用它:

这个函数在 distutils 中使用——我们可以从文档字符串中看到它的作用:

Docstring:
    Return the directory containing the Python library (standard or
    site additions).

    If 'plat_specific' is true, return the directory containing
    platform-specific modules, i.e. any module from a non-pure-Python
    module distribution; otherwise, return the platform-shared library
    directory.  If 'standard_lib' is true, return the directory
    containing standard Python library modules; otherwise, return the
    directory for site-specific modules.

    If 'prefix' is supplied, use it instead of sys.prefix or
    sys.exec_prefix -- i.e., ignore 'plat_specific'.
Run Code Online (Sandbox Code Playgroud)

因此,当使用 distutils(或构建在它之上的层)构建 python 包时,我们会在某些时候询问系统配置放置文件的正确位置,具体取决于它是系统还是平台库它'将进入 lib64 否则它将进入 lib。

如果您查看Fedora Python Packaging 文档或使用 fedora rpmdev 工具创建骨架 Python 规范,rpmdev-newspec python-foo您将看到有关 Fedora 如何基于调用此函数为 rpm 构建设置变量的详细注释。


Dis*_*ard 1

安装到 /usr/lib64 的任何源都应该来自安装 src 或 devel 软件包,默认情况下,这些软件包是由您的体系结构选择的。

/usr/lib 应该只包含 32 位库 - 同样 /usr/lib64 应该是 64 位版本。我发现 yum 偶尔会安装一些库的 32 位和 64 位版本,并且有一些库尚未移植到 64 位,因此如果您特定的应用程序或库已安装到 /usr/lib ,则其可能性是要么只是为了满足某些仅 32 位应用程序的依赖性,要么就是搞砸了。