崇高文字3:为plugin_host设置环境变量 [英] Sublime Text 3: Set Environment Variable for plugin_host

查看:92
本文介绍了崇高文字3:为plugin_host设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OSX上的Sublime Text 3.

Sublime Text 3 on OSX.

我正在编写一个插件,该插件加载了一个编写得特别糟糕的第三方Python模块,该模块依赖于环境变量的值来正常运行(尤其是 DYLD_LIBRARY_PATH ).

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).

当然,我可以在全局范围内进行设置,但是我希望Sublime插件可以独立存在.我注意到插件在Sublime本身的子进程中运行-有什么方法可以告诉Sublime在 plugin_host 进程中提供特定的环境变量,然后再将其剥离?

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?

如果没有,是否有人知道解决此问题的另一种方法?出于性能和简便性的原因,我非常希望python脚本是独立的,而不是调用利用该库的外部脚本.谢谢.

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.

推荐答案

查看

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...

这篇关于崇高文字3:为plugin_host设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆