Is the order reported by 'sys.path' the order in which packages are searched?

北慕城南 提交于 2020-01-02 07:15:12

问题


Does the order in which entries occur in the Python sys.path correspond to the order in which packages are found? For example I have

>>> from pprint import pprint     
>>> pprint(sys.path)
['',
 '/Library/Python/2.7/site-packages/ipython-0.14.dev-py2.7.egg',
 '/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg',
 '/Library/Python/2.7/site-packages/numpy-1.8.0.dev_3abd869_20121222-py2.7-macosx-10.8-intel.egg',
 '/Library/Python/2.7/site-packages/pymc-2.2-py2.7-macosx-10.8-intel.egg',
 '/Library/Python/2.7/site-packages/scikit_learn-0.13_git-py2.7-macosx-10.8-intel.egg',
 '/Library/Python/2.7/site-packages/scipy-0.12.0.dev_d631749_20121222-py2.7-macosx-10.8-intel.egg',
 '/Library/Python/2.7/site-packages/statsmodels-0.5.0-py2.7-macosx-10.8-intel.egg',
 '/Library/Python/2.7/site-packages/readline-6.2.4.1-py2.7-macosx-10.7-intel.egg',
 '/Library/Python/2.7/site-packages/nose-1.2.1-py2.7.egg',
 '/Library/Python/2.7/site-packages/six-1.2.0-py2.7.egg',
 '/Library/Python/2.7/site-packages/tornado-2.4.1-py2.7.egg',
 '/Library/Python/2.7/site-packages/pyzmq-2.2.0.1-py2.7-macosx-10.8-intel.egg',
 '/Library/Python/2.7/site-packages/patsy-0.1.0-py2.7.egg',
 '/Library/Python/2.7/site-packages/pip-1.2.1-py2.7.egg',
 '/Library/Python/2.7/site-packages/xattr-0.6.4-py2.7-macosx-10.8-intel.egg',
 '/Library/Python/2.7/site-packages/distribute-0.6.28-py2.7.egg',
 '/Library/Python/2.7/site-packages/astropy-0.3.dev2837-py2.7-macosx-10.8-intel.egg',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
 '/Library/Python/2.7/site-packages']

so that, in general, I've got

['',
 '/Library/Python/2.7/site-packages/PKG_WITH_EGG.egg',
 ...
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
 ...
 '/Library/Python/2.7/site-packages']

Does that mean that if a package I install (in 'site-packages') happens to have a .egg, it will supersede a version of the same package that might be in 'Extras' but that those (in 'site-packages') that do not have an .egg will be superseded by any version in 'Extras'?

来源:https://stackoverflow.com/questions/14882377/is-the-order-reported-by-sys-path-the-order-in-which-packages-are-searched

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!