Changing Python path under Mac OS for applications other than the terminal

笑着哭i 提交于 2019-12-13 00:07:53

问题


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.

For example, running

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

from Applescript gives a value of 13, but running

~/anaconda/bin/python -c 'import sys; print len(sys.path)'

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

回答1:


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



来源:https://stackoverflow.com/questions/21971324/changing-python-path-under-mac-os-for-applications-other-than-the-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!