scons“import os”是不是导入我的OS环境变量?

时间:2017-06-03 10:30:50

标签: python variables import environment scons

我正在测试scons在MAC上的行为,我尝试使用“import os”来构造环境变量,如下所示:

$cat SConstruct
import os
env=Environment(ENV=os.environ)
kkk=env['MY']

然后我试着运行它,似乎仍然没有通过“env = Environment(ENV = os.environ)”语句导入环境变量

$export MY='haha'
$/usr/local/bin/scons
scons: Reading SConscript files ...
KeyError: 'MY':
  File "/Users/my/SConstruct", line 3:
    kkk=env['MY']
  File "/usr/local/Cellar/scons/2.5.1/libexec/scons-local/SCons/Environment.py", line 410:
    return self._dict[key]

我正在使用scons版本:

$/usr/local/bin/scons -v
SCons by Steven Knight et al.:
    script: v2.5.1.rel_2.5.1:3735:9dc6cee5c168[MODIFIED], 2016/11/03 14:02:02, by bdbaddog on mongodog
    engine: v2.5.1.rel_2.5.1:3735:9dc6cee5c168[MODIFIED], 2016/11/03 14:02:02, by bdbaddog on mongodog
    engine path: ['/usr/local/Cellar/scons/2.5.1/libexec/scons-local/SCons']
Copyright (c) 2001 - 2016 The SCons Foundation

我哪里弄错了,怎么解决?

1 个答案:

答案 0 :(得分:1)

尝试:

import os
env=Environment(ENV=os.environ)
my_env_value=env['ENV']['MY']

由SCons运行的命令所呈现的环境是env ['ENV'],而不是env本身。