看来我有两个python2.6文件夹分别位于/ usr / lib和/ usr / lib64。 大多数python的东西(源代码)在/usr/lib64/python2.6中,但是在安装的软件包中它们已经被放入/usr/lib/python2.6
当请求python时,系统如何决定要去哪个目录,以及如何find已安装的打包的?
安装到/ usr / lib64的任何源代码都应该安装src或devel软件包,默认情况下,这些软件包是由您的架构挑选的。
/ usr / lib应该只有32位库 – / usr / lib64应该是64位版本。 我发现yum会偶尔安装一些库的32位和64位版本,还有一些库还没有移植到64位,所以如果你是特定的应用程序或库安装到/ usr / lib的可能性是它的要么只是为了满足一些32位只应用程序依赖或百胜搞砸了。
这个简单的答案是,没有任何C /本地扩展构build的软件包应该在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
有关包如何到达那里的更详细的答案需要对Python如何在自己的布局方面的工作有点了解。 我们感兴趣的是名为distutils的标准库的一部分。 这是主力,注意这里还有一些工具(setuptools)和一个叫fork的工具,目的是改进python包装。
有一个重要的补丁,fedora适用于这里谈论这使所有这些工作:
此修补程序有条件地应用于lib目录为lib64的体系结构的RPM 规范中:
如果我们看看这个补丁是如何变得麻烦的话:
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:
我们现在有一个distutils的条件,现在改变distutils.sysconfig.get_python_lib()在我们询问特定于平台或系统包的情况下返回的内容。 你可以尝试用python解释器中的各种选项来调用它:
这个函数在distutils中使用 – 我们可以从docstring中看到它的作用:
Docstring: Return the directory containing the Python library (standard or site additions). If 'plat_specific' is true, return the directory containing platform-specific modules, ie 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 -- ie, ignore 'plat_specific'.
所以当使用distutils构build一个python包(或者构build在它上面的图层)的时候,我们会在某种程度上要求系统configuration文件的放置位置,这取决于它是系统还是平台库,会在lib64中去,否则它会在lib中。
如果您查看Fedora Python Packaging文档或者使用fedora rpmdev工具创build骨架python spec rpmdev-newspec python-foo您将会看到Fedora如何根据调用此函数为rpm构build设置variables的详细注释。