0

知道,在 OS X 上,搜索包路径的默认顺序是(以 报告的形式pprint(sys.path))类似于:

['',
 '/Library/Python/X.X/site-packages/PKGS_WITH_EGGS.egg',
 ...
 '/System/Library/Frameworks/Python.framework/Versions/X.X/lib/pythonX.X/SOME_PLATFORM_PKGS,
 ...
 '/System/Library/Frameworks/Python.framework/Versions/X.X/Extras/lib/python',
  ...
 '/System/Library/Frameworks/Python.framework/Versions/X.X/lib/pythonX.X/OTHER_PLATFORM_PKGS,
 ...
'/System/Library/Frameworks/Python.framework/Versions/X.X/Extras/lib/python/PyObjC',
'/Library/Python/X.X/site-packages']

例如,在我的系统(OS 10.9)上,我有:

['',
'/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']

其他系统似乎采用了类似的结构。

这种排序的逻辑是什么,特别是为什么首先寻找“鸡蛋”,为什么site-packages最后使用?

4

0 回答 0