python包和目录有什么不同_Python的“其他”目录和“站点包”目录之间有什么区别?...

1586010002-jmsa.png

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.

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

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/

解决方案

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

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.

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.

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.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值