在 MacPorts 安装 Python 后修复 Python sys.path

在 MacPorts 安装 Python 后修复 Python sys.path

所以我重新安装了 MacPorts Python。我有port select --set python python27which python返回正确的位置,即/opt/local/bin。现在,当我在 Python 解释器中导入模块时,我相信首先在非 MacPorts 目录中查找模块,即/Library/Python/2.7/site-packages/

我相信这是因为这些输出print(sys.path)

['',
 '/Library/Python/2.7/site-packages/nose-1.1.2-py2.7.egg',
 '/Library/Python/2.7/site-packages/DateUtils-0.5.1-py2.7.egg',
 '/Library/Python/2.7/site-packages/ipython-0.13.dev-py2.7.egg',
 '/Library/Python/2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.7-intel.egg',
 '/Library/Python/2.7/site-packages/numpy-1.7.0.dev_3cb783e_20120427-py2.7-macosx-10.7-x86_64.egg',
 '/Library/Python/2.7/site-packages/pandas-0.7.3_20120507-py2.7-macosx-10.7-x86_64.egg',
 '/Library/Python/2.7/site-packages/pymc-2.2beta-py2.7-macosx-10.7-intel.egg',
 '/Library/Python/2.7/site-packages/scipy-0.10.1_20120427-py2.7-macosx-10.7-x86_64.egg',
 '/Library/Python/2.7/site-packages/statsmodels-0.4.0-py2.7-macosx-10.7-intel.egg',
 '/Library/Python/2.7/site-packages/readline-6.2.2-py2.7-macosx-10.7-intel.egg',
 '/Library/Python/2.7/site-packages/pip-1.1-py2.7.egg',
 '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
 '/Library/Python/2.7/site-packages',
 '/Library/Python/2.7/site-packages/PIL']

我的问题是:所有这些都是/Library/Python/2.7/site-packages/.....etc.必要的吗?或者我可以删除它们,这样 Python 只会浏览/opt/目录吗?然后,如果找不到它,它会查找最后添加的这两个条目:/Library/Python...寻找其他包?

相关内容