Sublime Text 3: Set Environment Variable for plugin_host

霸气de小男生 提交于 2019-12-08 00:05:22

问题


Sublime Text 3 on OSX.

I am writing a plugin that loads up a particularly poorly-written 3rd-party Python module that relies on the value of an Environment Variable to function properly (in particular, DYLD_LIBRARY_PATH).

Of course, I could set this globally, but I would love for the Sublime Plugin to be self-contained. I notice that plugins run in a child process of Sublime itself - is there any way to tell Sublime to provide the plugin_host process with a particular Environment Variable before it spins it off?

If not, does anyone know of another way to solve this problem? For performance and simplicity reasons, I would greatly prefer to have the python script be self-contained, rather than calling out to an external script that utilizes the library. Thank you.


回答1:


Check out os.putenv() and os.environ for details on setting environment variables from Python. So, for your case, before importing your 3rd-party module, use something like this:

import os
os.environ['DYLD_LIBRARY_PATH'] = '/usr/lib/foo:' + os.environ.get('DYLD_LIBRARY_PATH')

import third_party
# and so on...


来源:https://stackoverflow.com/questions/21565189/sublime-text-3-set-environment-variable-for-plugin-host

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