10

我的问题假设您在那些不同的 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

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

4

2 回答 2

7

是的,它不同,例如在 CentOS 5.6 中,python 外部模块被放置在/usr/lib/python2.6/site-packages. 实际上dist-packagesdebian 特定的目录

于 2012-08-06T09:24:20.767 回答
1

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

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

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

干杯

于 2012-08-06T09:30:06.893 回答