【问题标题】:Are the paths to the python standard library and to the dist-packages different for different linux distributions(Debian, Redhat, Slackware, ...)?对于不同的 Linux 发行版(Debian、Redhat、Slackware、...),python 标准库和 dist 包的路径是否不同?
【发布时间】:2012-08-03 06:15:39
【问题描述】:

我的问题假设您在这些不同的 linux 发行版上使用相同的 python 版本。我还从我的问题中排除了虚拟环境。

我使用基于 Debian 的发行版 Ubuntu。 python标准库(用python编写的模块/包)的路径是/usr/lib/python2.7。 “外部”python 包的路径是/usr/local/lib/python2.7/dist-packages

非常感谢以独立于系统的方式获取这些路径。

编辑1

我找到了:

>>> from distutils.sysconfig import get_python_lib
>>> print get_python_lib()
/usr/local/lib/python2.7/dist-packages

>>> print get_python_lib(standard_lib=True)
/usr/lib/python2.7

编辑2

我认为第一次编辑中的方法已被弃用,因为我只能找到它,直到 python2.5 文档。新方法(在 2.7 文档中):

>>> import sysconfig
>>> sysconfig.get_path_names()
('stdlib', 'platstdlib', 'purelib', 'platlib', 'include', 'scripts', 'data')
>>> print sysconfig.get_path('platlib')
/usr/local/lib/python2.7/dist-packages

我还没有找到如何使用 sysconfig 找到 /usr/lib/python2.7。现在,我将使用已弃用的方法,并假设这会产生预期的结果。

【问题讨论】:

  • 你为什么要问——你想要这些位置的跨平台快捷方式吗?
  • 我还没有找到如何使用 sysconfig 找到/usr/lib/python2.7 这应该是stdlib 键下的路径。不过,在 64 位系统上,这很可能是 /usr/lib64/python2.7

标签: python linux path linux-distro


【解决方案1】:

是的,它不同,例如在 CentOS 5.6 中,python 外部模块放在/usr/lib/python2.6/site-packages 中。其实dist-packages就是debian specific directory

【讨论】:

  • 和 opensuse 将使用 lib64(在 64 位上)
【解决方案2】:

你可以从这里阅读更多关于这个主题的内容 http://www.aosabook.org/en/packaging.html, $ 如果我们想将包部署到软件存储库,它会讨论打包和库位置。

我已经在博客中谈到了一点,请看看并给我一些反馈

http://insidepython.wordpress.com/2012/08/03/quickintro/

干杯

【讨论】:

  • 我不担心打包(目前),我的应用程序使用这些路径。
猜你喜欢
  • 1970-01-01
  • 2020-03-17
  • 2019-04-03
  • 2016-10-08
  • 2021-09-04
  • 2011-09-25
  • 1970-01-01
  • 2020-08-16
  • 2010-12-03
相关资源
最近更新 更多