我试图将此目录添加到我的python2.7路径
/usr/local/lib/python2.7/site-packages
我可以使用:
sys.path.append('/usr/local/lib/python2.7/site-packages')
或者我也可以将此行添加到我的〜/ .profile或〜/ .bashrc
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
但是,这会将同一目录添加到我的python2.6路径
import sys
from pprint import pprint as pp
pp(sys.path)
['',
'/usr/local/lib/python2.7/site-packages',
'/Users/Leo/Desktop/ReactiveFlows/Homework/HW1/HW1/Cantera',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload',
'/Library/Python/2.6/site-packages',
'/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC']
答案 0 :(得分:2)
有很多方法可以做到这一点,如Modifying Python’s Search Path中所述。
一种方法是将local.pth
文件添加到/Library/Python/2.7/site-packages
(或已在Python2.7的sys.path
中列出的任何目录),其中包含该行
/usr/local/lib/python2.7/site-packages