Python的“其他"目录与“站点包"目录之间有什么区别? [英] What is the difference between Python's 'Extras' and 'site-packages' directories?

查看:165
本文介绍了Python的“其他"目录与“站点包"目录之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对OS X上的Python使用其他"和站点包"中的包的方式感到困惑.特别是,我对在这些目录中看到的内容,目录中重复的软件包如何相互影响以及应该在何处放置安装的软件包感到困惑.

I'm confused about the way Python, on OS X, uses the packages in 'Extras' and 'site-packages'. In particular, I'm confused about the what I see in these directories, and how duplicate packages in the directories affect each other, and where I should put packages that I install.

我假设'Extras' 1 是不属于核心Python的软件包的位置,但是这些软件包仍在给定的平台上分发.例如,OS X随PyObjCtwistednumpy一起分发.这些都可以在其他"中找到.我还假设"site-packages" 2 是我随后安装软件包的位置,并且该目录为空或新"计算机上不存在.此外,我假设安装新软件包将使该版本独自保留在其他"中,而将我所做的所有更新都放置在站点软件包"中,而这些更新将掩盖"那些在其他"中. (因此,例如,只需删除"site-packages"即可恢复默认安装.)

I had assumed that 'Extras'1 was the location for packages that are not part of core Python, but that were nonetheless distributed with a given platform. For example, OS X, is distributed with PyObjC, twisted, and numpy, among others; and these are found in 'Extras'. I had also assumed that 'site-packages'2 is where packages that I subsequently install go, and that the directory is empty or absent on a "fresh" machine. Furthermore I'd assumed that installing a new package would leave the version in 'Extras' alone, and place any updates I do in 'site-packages', where they would "mask" those in 'Extras'. (So for example, the default installation could simply be restored by deleting 'site-packages'.)

让我感到困惑的是,我的其他"目录的内容正在减少.与新安装的OS X(10.8.2)上的内容相比,我当前配置的附加项"缺失了

What confuses me is that the contents of my 'Extras' directory is dwindling. Compared with the contents on a fresh OS X (10.8.2) install, the 'Extras' for my current configuration is missing

altgraph
altgraph-0.9-py2.7.egg-info
dateutil
macholib
macholib-1.4.2-py2.7.egg-info
modulegraph
modulegraph-0.9.1-py2.7.egg-info
numpy #though numpy-1.6.1-py2.7.egg-info is there
pkg_resources.py  # though .pyc is there
py2app
py2app-0.6.3-py2.7.egg-info
setuptools  # though setuptools-0.6c12dev_r88846-py2.7.egg-info is there
site.py  # though .pyc and .pyo are there
xattr
xattr-0.6.2-py2.7.egg-info
zope
zope.interface-3.5.1-py2.7.egg-info

,并且在全新安装中找不到两个其他文件

and has two additional files not found in the fresh install

pkg_resources.py.OLD.1356069438.31
setuptools-0.6c12dev_r88846-py2.7.egg-info.OLD.1356069438.31
setuptools.OLD.1356069438.31

据我所知,这些都是我自己更新过的所有软件包,所有版本均位于站点软件包"中.

To the best of my recollection, these are all packages that I've updated myself, and versions of all are present in 'site-packages'.

额外"目录的内容是否应该以这种方式减少"?更新位于其他"中的软件包是否会将其移动"到站点软件包",还是应该单独保留其他"版本并仅由站点软件包"中的那些掩盖"?

Is the contents of the 'Extras' directory supposed to "dwindle" in this way? Does updating a package that is in 'Extras' "move" it to 'site-packages', or should the 'Extras' versions be left alone and simply "masked" by those in 'site-packages'?

1:/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
2:/Library/Python/2.7/site-packages/

1:/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
2: /Library/Python/2.7/site-packages/

推荐答案

OSX(和Linux)似乎不喜欢在python发行版的默认安装目录中安装额外的python软件包.

OSX (and Linux) does not seem to like to install extra python packages in the default installation directory of python distribution.

pip可以搜索(就像python本身一样)查找已安装的模块,如果进行升级,则会卸载旧版本并在您要的位置安装新版本,默认为站点软件包.如果您仔细查看pip的输出,它将告诉您删除了什么以及安装了什么.

pip can search (like python itself does) for installed modules, and if you do an upgrade will de-install the old version and install the new version in the place you asked for, defaulting to site-packages. If you closely look at the output of pip it will tell you what it removed and what it installed.

因此,仅当您告诉pip安装到Extras目录,或者默认情况下要为OSX修补pip以进行安装时,

So only if you tell pip to install to the Extras directory, or would have a pip patched to do so for OSX by default, that would work.

删除旧版本实际上是一件好事,否则导入的模块版本将取决于您的搜索路径(sys.path),并且容易出错.

It is actually a good thing the older versions are removed, as otherwise the version of a module you import would be depending on your search path (sys.path) and that is kind of error prone.

是否应该下降是可以争论的,但这是您使用pip进行升级的正常结果.

Whether it is supposed to dwindle can be argued, but it is a normal result of the way you do your upgrades with pip.

这篇关于Python的“其他"目录与“站点包"目录之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆