sublime text environment variables not present

  • Last Update :
  • Techknowledgy :

When I make a modification to, e.g. $PYTHONPATH in my .bashrc, this change is not noticed by ST3.,I’m having difficulty with ST3 environment variable management,It requires a restart and opening from terminal via subl for the environment variables to be visible to the python interpreter(!) This is quite frustrating behavior.,In case you want to modify the environment of an external python interpreter which runs your scripts, you can create a custom python built script with some extra environment variables to be passed to it. You still won’t be able to place them into the .bashrc but directly into the *.sublime-build

using settings like the following, make sure your environment file, env_file, is set for your operating system. Also make sure you’ve set your PATH variable.

// Settings in here override those in "/ProjectEnvironment/ProjectEnvironment.sublime-settings",
{
   // If true some debugging information will be preinted on console
   "print_output": false,
   // If true some variables available in Sublime's API, will be exposed as
   // standard environment variables.
   // these are:
   // "project_path", "project", "project_name", "project_base_name", "packages"
   "set_sublime_variables": false,
   // It may be useful to add a prefix to those variables so that they don't confict with yours
   "sublime_variables_prefix": "",
   // those variables can be all capitalised if you wish. "project" will become "PROJECT"
   "sublime_variables_capitalized": false,
   // files with this extensions will be run through source_vars(.bat|.sh)
   // DON'T FORGET THE DOT!
   "command_line_to_wrap_extensions": [
      ".bat",
      ".sh"
   ],
   // This is only for windows, since Mac and Linux can use shebang:
   "execute_ext_with": {
      ".py": "python",
      ".zsh": "zsh",
      ".sh": "zsh",
      ".bash": "bash"
   },
   "settings": {
      "project_environment": {
         "env": {},
         "env_file": "",
         "windows": {},
         "osx": {
            "PATH": "$PATH:/usr/local/bin",
            "env_file": "~/.zshenv"
         },
         "linux": {}
      }
   }
}

Suggestion : 2

Quick workaround:

$ cd~/.config/sublime - text - 3 / Packages
$ mkdir - p Default
$ echo 'import os; os.environ["LC_ALL"] = os.environ["LANG"] = "C.UTF-8"' > Default / echo.py

Suggestion : 3

A plugin for **SublimeText 3** that allows to set environment variables in the .sublime-project file. ,A plugin for SublimeText that allows to set environment variables in the .sublime-project file. ,It will then collect all the environment variables in that child process and return them to the main process where the new variables, or the variables that have a different values, will be appended to the main environment. ,command_line_to_wrap_extensions A list of extension that the plugin will treat as command line file. Files with these extension will be “sourced” in an external process and, if they set variables, the environment will be compared to the base environment in Sublime. If there are variables not present in the base Sublime environment, they will be added to it. The default value for this is [".bat", ".sh"]

"execute_ext_with": {
   ".py": "python"
}
"settings": {
   "project_environment": {}
}
"settings": {
   "project_environment": {
      "env": {},
      "env_file": "",
      "windows": {},
      "osx": {},
      "linux": {}
   }
}
{
   "folders": [{
      "path": "."
   }],
   "settings": {
      "project_environment": {
         "print_output": true,
         "set_sublime_variables": true,
         "sublime_variables_prefix": "sublime_",
         "sublime_variables_capitalized": true,
         "env_file": "./env/generic_env.py"
         "env": {
            "CROSS_PLATFORM_ENV": "cross_platform_env"
         },
         "windows": {
            "env": {
               "IN_LINE_ENV": "in_line_env_window"
            },
            "env_file": "./env/env_win.bat"
         },
         "osx": {
            "env": {
               "IN_LINE_ENV": "in_line_env_mac"
            },
            "env_file": "./env/env_osx.sh"
         },
         "linux": {
            "env": {
               "IN_LINE_ENV": "in_line_env_linux"
            },
            "env_file": "./env/env_linux.sh"
         }
      }
   }
}
{
   "folders": [{
      "path": ".",
      "path_template": "$MY_PATH"
   }],
   "settings": {
      "project_environment": {
         "windows": {
            "env": {
               "MY_PATH": "some/location/windows"
            }
         },
         "osx": {
            "env": {
               "MY_PATH": "some/location/mac_osx"
            }
         },
         "linux": {
            "env": {
               "MY_PATH": "some/location/linux"
            }
         }
      }
   }
}
{
   "name": "Super Test",
   "shell_cmd": "echo %MY_TEST_VARIABLE%"
}

Suggestion : 4

External programs used in build systems need to be in your PATH. As a quick test, you can try to run them from the command line first and see whether they work. Note, however, that your shell’s PATH variable might differ to that seen by Sublime Text due to your shell’s profile. Remember that you can use the path option in a .build-system file to add directories to PATH without changing your system’s settings.,Essentially, build systems are configuration data for an external program. In them, you specify the switches, options and environment information you want passed to the executable.,Array containing the command to run and its desired arguments. If you don’t specify an absolute path, the external program must be in your PATH, one of your system’s environmental variables.,When error information is captured, you can navigate to error instances in your project’s files with F4 and Shift+F4. If available, the captured error message will be displayed in the status bar.

{
   "cmd": ["python", "-u", "$file"],
   "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
   "selector": "source.python"
}
{
   "cmd": ["ant"],
   "file_regex": "^ *\\[javac\\] (.+):([0-9]+):() (.*)$",
   "working_dir": "${project_path:${folder}}",
   "selector": "source.java",

   "windows": {
      "cmd": ["ant.bat"]
   }
}
$ {
   project_name: Default
}
$ {
   file / \.php / \.txt /
}