Sublime Forum

"TERM environment variable not set." when Python build (on mac)

#1

Hi everybody,

First of all, note that I am a newbie with ST3 (but not with Python).

I have a “little” problem that I can not explain. And that makes me totally crazy.

When I build a Python script, I have the following warning: “TERM environment variable not set” (but the script is still executed correctly). I have the following configuration:

  • ST3 latest version build 3126, out of the box and paid :wink: ;
  • macOS Sierra;
  • Python 3.5.2 (Anaconda 4.2, latest version for mac).

When I make an “echo $TERM” in a (bash) terminal the result is “xterm-256color”. So it seems to me that my problem comes from:

  • the configuration of ST3;
  • or the configuration of Anaconda;
  • or ???.

BUT the strangest thing is that I have two computers (desktop and laptop) with (apparently) exactly the same configuration. On the desktop (mac pro late 2013, love it), no problem at all. But on the laptop (MBA 11", love it too) I have this f*****g warning.

Any ideas about this?

Thank you in advance,

Regards,

Pierre BÉJIAN
(France)

0 Likes

#2

What build system are you using to invoke the build? The default python version, something from a package, custom one?

My Mac is running 10.10.5 currently. From bash the terminal is xterm-256color but from Sublime in this simplistic example of executing a shell script, the result is dumb (I’m kinda childish, so I chucked).

I don’t know is the reason for that is python related or sublime related, though. On my linux box the same operation produces linux as the terminal instead.

In either case, it seems to be set to something (if not what you would expect).

0 Likes

#3

Hi,

I’m using the default python build system.

I still don’t understand, but following your example I made some test:

  • add export TERM=“xterm-256color” to my .bash_profile
  • add a Bash.sublime-build with the “-l” option (so the .bash_profile is read before running a bash script)

Maybe I just have to make something analog for Python (a personal Python build system). Not sure to know exactly how to do that. But I can search on the web…

Thanks,
Pierre

0 Likes

#4

OK, interesting. There are at least three potential solutions to this thing.

For background, the default Python build system uses shell_cmd to execute python -u on the current file. Internally that is executed (on OSX) as /bin/bash -l -c python

That said, the internal code that is used to actually do that execution uses the python value of os.environ as a base environment, updated by any environment that might be passed into the build system. The build system itself sets a value for PYTHONIOENCODING and nothing else.

If I open the Sublime console with Ctrl+` and execute the following python code, there is no setting listed for TERM:

import os
print (os.environ)

I added an explicit setting for TERM in my ~/.bashrc (I have my ~/.bash_profile set to source that file) and as soon as I did that, running my above example again (without starting Sublime), the terminal was reported as xterm-256color.

You can go about fixing this in three ways (although based on your image above, you may already be using the first version of the fix):

  1. Make sure that your .bash_profile somehow explicitly sets TERM to some value. That should get picked up as long as you use the default python build system (or indeed any build system).

  2. You can add the setting below to your user preferences to cause an extra environment to be included on every build to set it for you. You could also just put that into the e.g. python specific settings if you wanted to.

  3. Modify the default Python build to include the setting below along with the setting it already has.

    "build_env": {"TERM": "xterm-256color"}
0 Likes

#5

This most likely fails for the same reason as why https://packagecontrol.io/packages/Fix%20Mac%20 path is needed: you launch ST from the dock, where it doesn’t inherit environment variables exported by .bash_profile.

The $TERM variable is used by the anaconda build I assume but I don’t know what they use it for. Probably executing the build in a separate terminal window.

I would have to analyze the source code of FixMacPath in order to see whether it would solve your problem though (am on mobile).

0 Likes