TL; DR;
Replace:
env = dict(line.split('=', 1) for line in lines)
in ~/.config/sublime-text-3/Packages/SublimeREPL/repls/subprocess_repl.py with
env = dict(line.split('=', 1) for line in lines if '=' in line)
(Thanks @MichaelOhlrogge for the shorter syntax)
Why does it work
@Develucas's solution helped me solve my problem. I did not have the problem that he described, but his research helped.
In my case, there was a greeting in the login shell. So, bash --login -c env (the command specified in the SublimeREPL.sublime-settings file in the getenv_command parameter) printed something like this:
Hello, parth! USER=parth SHELL=/bin/bash . . .
It turns out that SublimeREPL uses the output of this command to load environment variables - as indicated in the comment above the getenv_command parameter:
// On POSIX system SublimeText launched from GUI does not inherit // a proper environment. Often leading to problems with finding interpreters // or not using the ones affected by changes in ~/.profile / *rc files // This command is used as a workaround, it launched before any subprocess // repl starts and it output is parsed as an environment "getenv_command": ["/bin/bash", "--login", "-c", "env"],
The code analyzing this output is similar to this (in the ~/.config/sublime-text-3/Packages/SublimeREPL/repls/subprocess_repl.py for ST3):
def getenv(self, settings): """Tries to get most appropriate environent, on windows it os.environ.copy, but on other system we'll try get values from login shell""" getenv_command = settings.get("getenv_command") if getenv_command and POSIX: try: output = subprocess.check_output(getenv_command) lines = output.decode("utf-8", errors="replace").splitlines() env = dict(line.split('=', 1) for line in lines) return env except: import traceback traceback.print_exc() error_message( "SublimeREPL: obtaining sane environment failed in getenv()\n" "Check console and 'getenv_command' setting \n" "WARN: Falling back to SublimeText environment")
The line env = dict(line.split('=', 1) for line in lines) causes a problem because the first line in the output of bash --login -c env does not have = . Therefore, I changed this line to ignore lines that are not = :
env = dict(line.split('=', 1) for line in lines if '=' in line)
And that solved the problem for me. Remember to restart Sublime Text after modifying this file.