在Mac OS下为终端以外的应用程序更改Python路径

时间:2014-02-23 16:59:27

标签: python macos terminal finder pythonpath

我有一个Python脚本,我希望能够在Finder或Quicksilver中轻松运行。不幸的是,任何运行不使用终端的脚本的方法都无法找到我的库。

例如,运行

do shell script "~/anaconda/bin/python -c 'import sys; print len(sys.path)'"
来自Applescript的

值为13,但正在运行

~/anaconda/bin/python -c 'import sys; print len(sys.path)'
来自终端的

给出了15.这让我觉得.bash_profile可能不是修改我的Python路径的最佳位置。有没有办法对Python路径进行更改,这会影响终端和其他所有内容?如果是这样,那是修改Python路径的首选方法吗?

以下是我的设置的一些版本信息:

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

1 个答案:

答案 0 :(得分:1)

您可以设置环境变量PYTHONPATH。现在,我不是Mac用户,但是根据一些研究,我要说你必须修改~/.MacOSX/environment.plist,如下所述:https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/EnvironmentVars.html#//apple_ref/doc/uid/20002093-BCIJIJBH

相关问题