在Mac OS下为终端以外的应用程序更改Python路径
我有一个Python脚本,希望能够在Finder或Quicksilver上大惊小怪地运行.不幸的是,任何不使用终端运行脚本的方式都找不到我的库.
I have a Python script that I'd like to be able to run with a minimum of fuss from the Finder or Quicksilver. Unfortunately, any way of running the script that doesn't use the terminal can't find my libraries.
例如,运行
do shell script "~/anaconda/bin/python -c 'import sys; print len(sys.path)'"
Applescript的
值为13,但正在运行
from Applescript gives a value of 13, but running
~/anaconda/bin/python -c 'import sys; print len(sys.path)'
终端上的
给出15.这使我认为.bash_profile
可能不是修改我的Python路径的最佳位置.有没有办法对Python路径进行更改,使其同时影响终端和其他所有内容?如果是这样,那是修改Python路径的首选方法吗?
from the terminal gives 15. This makes me think that .bash_profile
may not be the best place to modify my Python path. Is there a way to make changes to the Python path that will affect both the terminal and everything else? If so, is that the preferred method of modifying the Python path?
以下是我的设置的一些版本信息:
Here's some version info for my setup:
Python 2.7.6 |Anaconda 1.8.0 (x86_64)| (default, Nov 11 2013, 10:49:09)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
您可以设置环境变量 PYTHONPATH .现在,我不是Mac用户,但是根据一些研究,我说您必须按以下说明修改~/.MacOSX/environment.plist
:
You can set the environment variable PYTHONPATH. Now, I'm not a Mac user, but from some research I'd say you have to modify ~/.MacOSX/environment.plist
as described here: https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/EnvironmentVars.html#//apple_ref/doc/uid/20002093-BCIJIJBH