问题:dist-packages和site-packages有什么区别?

我对python软件包的安装过程有些不满意。具体来说,安装在dist-packages目录和site-packages目录中的软件包之间有什么区别?

I’m a bit miffed by the python package installation process. Specifically, what’s the difference between packages installed in the dist-packages directory and the site-packages directory?


回答 0

dist-packages是特定于Debian的约定,也存在于其衍生版本中,例如Ubuntu。当模块从Debian软件包管理器进入以下位置时,它们将安装到dist-packages中:

/usr/lib/python2.7/dist-packages

由于easy_installpip是从软件包管理器安装的,因此它们也使用dist-packages,但是它们将软件包放在此处:

/usr/local/lib/python2.7/dist-packages

Debian Python Wiki

dist-packages而不是site-packages。从Debian软件包安装的第三方Python软件进入dist软件包,而不是站点软件包。这是为了减少系统Python与您可能手动安装的任何源Python构建之间的冲突。

这意味着,如果您从源代码手动安装Python,它将使用site-packages目录。这使您可以将两个安装分开,特别是因为Debian和Ubuntu在许多系统实用程序中都依赖Python的系统版本。

dist-packages is a Debian-specific convention that is also present in its derivatives, like Ubuntu. Modules are installed to dist-packages when they come from the Debian package manager into this location:

/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:

/usr/local/lib/python2.7/dist-packages

From the Debian Python Wiki:

dist-packages instead of site-packages. Third party Python software installed from Debian packages goes into dist-packages, not site-packages. This is to reduce conflict between the system Python, and any from-source Python build you might install manually.

This means that if you manually install Python from source, it uses the site-packages directory. 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.


回答 1

dist-packages是debian专用的目录,apt朋友可以在其中安装他们的东西,并且site-packages是标准pip目录。

问题是-当不同目录中存在相同软件包的不同版本时,会发生什么?

我对这个问题的解决方案是建立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

(如果您不使用gnu工具,请删除该-v选项)。

dist-packages is the debian-specific directory where apt and friends install their stuff, and site-packages is the standard pip directory.

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:

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).


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。