简体   繁体   English

dist-packages 和 site-packages 有什么区别?

[英]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_installpip是从包管理器安装的,它们也使用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 约定的要点是将三组包分开:

  1. python packages installed by apt apt安装的python个包
  2. packages installed by root user with /usr/bin/pip3 root 用户使用/usr/bin/pip3安装的包
  3. packages installed by root user with their own /usr/local/bin/pip3 root 用户使用自己的/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.

相关问题 &#39;dist-packages&#39;与&#39;site-packages&#39;中的Python模块 - Python module in 'dist-packages' vs. 'site-packages' Python的“其他”目录和“站点包”目录之间有什么区别? - What is the difference between Python's 'Extras' and 'site-packages' directories? Ubuntu + virtualenv =乱七八糟? virtualenv讨厌dist-packages,想要网站包 - Ubuntu + virtualenv = a mess? virtualenv hates dist-packages, wants site-packages “pkgs”目录和“site-packages”目录有什么区别? [蟒蛇] - What is the difference between the 'pkgs' directory and the 'site-packages' directory? [Anaconda] anaconda2 / Lib / site-packages /之间有什么区别 <pkg> 和anaconda2 / pkgs / <pkg> ? - What's the difference between anaconda2/Lib/site-packages/<pkg> and anaconda2/pkgs/<pkg>? python的站点包目录是什么? - What is python's site-packages directory? python:用户站点中的包不覆盖ubuntu上的dist-packages - python: Packages in user-site not overriding dist-packages on ubuntu Django安装在dist-packages中 - Django installed in dist-packages Python dist-packages权限 - Python dist-packages permissions 不小心删除了 dist-packages 文件夹,现在该怎么办? - Accidentally removed dist-packages folder, what to do now?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM