'Env vars for kernels'

@property
def env(self):

    sc_path = osp.join(self.spy_path, 'utils', 'site')
    spy_pythonpath = CONF.get('main', 'spyder_pythonpath', default=[])
    default_interpreter = CONF.get('main_interpreter', 'default')
    if default_interpreter:
        pathlist = ([sc_path] + spy_pythonpath)
    else:
        pathlist = ([sc_path, self.spy_path] + spy_pythonpath)
    pypath = add_pathlist_to_PYTHONPATH([], pathlist, ipyconsole=True, drop_env=(not default_interpreter))
    umr_namelist = CONF.get('main_interpreter', 'umr/namelist')
    if PY2:
        original_list = umr_namelist[:]
        for umr_n in umr_namelist:
            try:
                umr_n.encode('utf-8')
            except UnicodeDecodeError:
                umr_namelist.remove(umr_n)
        if (original_list != umr_namelist):
            CONF.set('main_interpreter', 'umr/namelist', umr_namelist)
    env_vars = {'EXTERNAL_INTERPRETER': (not default_interpreter), 'UMR_ENABLED': CONF.get('main_interpreter', 'umr/enabled'), 'UMR_VERBOSE': CONF.get('main_interpreter', 'umr/verbose'), 'UMR_NAMELIST': ','.join(umr_namelist)}
    env_vars.update(pypath)
    for (key, var) in iteritems(env_vars):
        if PY2:
            try:
                unicode_var = to_text_string(var)
            except UnicodeDecodeError:
                try:
                    unicode_var = to_unicode_from_fs(var)
                except:
                    unicode_var = ''
            env_vars[key] = to_binary_string(unicode_var, encoding='utf-8')
        else:
            env_vars[key] = to_text_string(var)
    return env_vars
