[英]What's the difference between dist-packages and site-packages?
I'm a bit miffed by the python package installation process.我对 python package 安装过程有点恼火。 Specifically, what's the difference between packages installed in the dist-packages directory and the site-packages directory?
具体来说,安装在 dist-packages 目录和 site-packages 目录中的包有什么区别?
dist-packages
is a Debian-specific convention that is also present in its derivatives, like Ubuntu. dist-packages
是 Debian 特定的约定,也存在于其衍生产品中,如 Ubuntu。 Modules are installed to dist-packages
when they come from the Debian package manager into this location:当模块从 Debian 包管理器进入以下位置时,它们会安装到
dist-packages
:
/usr/lib/python2.7/dist-packages
Since easy_install
and pip
are installed from the package manager, they also use dist-packages
, but they put packages here:由于
easy_install
和pip
是从包管理器安装的,它们也使用dist-packages
,但它们把包放在这里:
/usr/local/lib/python2.7/dist-packages
From the Debian Python Wiki :来自Debian Python Wiki :
dist-packages instead of site-packages.
dist-packages 而不是 site-packages。 Third party Python software installed from Debian packages goes into dist-packages, not site-packages.
从 Debian 软件包安装的第三方 Python 软件进入 dist-packages,而不是 site-packages。 This is to reduce conflict between the system Python, and any from-source Python build you might install manually.
这是为了减少系统 Python 与您可能手动安装的任何源 Python 构建之间的冲突。
This means that if you manually install Python from source, it uses the site-packages
directory.这意味着如果您从源代码手动安装 Python,它将使用
site-packages
目录。 This allows you to keep the two installations separate, especially since Debian and Ubuntu rely on the system version of Python for many system utilities.这允许您将两个安装分开,特别是因为 Debian 和 Ubuntu 的许多系统实用程序依赖于 Python 的系统版本。
Debian (and Ubuntu) has introduced its own convention Debian(和 Ubuntu) 引入了自己的约定
# python3 -m site
on Ubuntu Focal gives在 Ubuntu 上,Focal 提供
sys.path = [
'/qpid-dispatch',
'/usr/lib/python38.zip',
'/usr/lib/python3.8',
'/usr/lib/python3.8/lib-dynload',
'/usr/local/lib/python3.8/dist-packages',
'/usr/lib/python3/dist-packages',
]
USER_BASE: '/root/.local' (doesn't exist)
USER_SITE: '/root/.local/lib/python3.8/site-packages' (doesn't exist)
ENABLE_USER_SITE: True
The convention, as described in the linked mailing list, is that python deb packages installed by the distribution package manager go into /usr/lib/python3/dist-packages
and packages installed using sudo pip3
go into /usr/local/lib/python3.8/dist-packages
.如链接邮件列表中所述,约定是 python deb 包由分发 package 管理器 go 安装到
/usr/lib/python3/dist-packages
中,使用sudo pip3
go 安装到/usr/local/lib/python3.8/dist-packages
中/usr/local/lib/python3.8/dist-packages
。
If you compile and install your own Python interpreter, it will default to placing itself in /usr/local
, with /usr/local/bin/pip3
installs going into /usr/local/lib/pythonX.Y/site-packages
.如果您编译并安装自己的 Python 解释器,它将默认将自己放置在
/usr/local
中,而/usr/local/bin/pip3
安装进入/usr/local/lib/pythonX.Y/site-packages
。
The point of the Debian convention is to keep the three sets of packages separate: Debian 约定的要点是将三组包分开:
apt
apt
安装的python个包/usr/bin/pip3
/usr/bin/pip3
安装的包/usr/local/bin/pip3
/usr/local/bin/pip3
安装的包dist-packages
is the debian-specific directory where apt
and friends install their stuff, and site-packages
is the standard pip
directory. dist-packages
是 debian 特定的目录, apt
和朋友在其中安装他们的东西,而site-packages
是标准的pip
目录。
The problem is -- what happens when different versions of the same package are present in different directories?问题是——当同一个包的不同版本存在于不同的目录中时会发生什么?
My solution to the problem is to make dist-packages
a symlink to site-packages
:我对这个问题的解决方案是使
dist-packages
成为指向site-packages
的符号链接:
for d in $(find $WORKON_HOME -type d -name dist-packages); do
pushd $d
cd ..
if test -d dist-packages/__pycache__; then
mv -v dist-packages/__pycache__/* site-packages/__pycache__/
rmdir -v dist-packages/__pycache__
fi
mv -v dist-packages/* site-packages/
rmdir -v dist-packages
ln -sv site-packages dist-packages
popd
done
(if you are not using gnu tools, remove the -v
option). (如果您不使用 gnu 工具,请删除
-v
选项)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.