Setting environment variables

Issue #109 closed
Ronald Oussoren
repo owner created an issue


1) It should be possible to set LANG/LC_* variables through Info.plist, but that currently doesn't work.

2) It may be useful to have a py2app option for this, although explicitly updating info.plist isn't too bad.

See also

Comments (5)

  1. Ronald Oussoren reporter

    Duh, setting LC_CTYPE won't work because py2app sets LC_CTYPE to "en_US.UTF-8" during Py_Initialize and that means os.environment will contain that value instead of the one mentioned in the environment.

  2. Ronald Oussoren reporter

    You can use the key LSEnvironment in the 'Info.plist' file for this.

    Adding this can be done using the file, for example:

    ... # other code

    You cannot override LC_CTYPE with this because py2app overrides that when initialising Python.

    BTW. A better way is to actually get the locale from the system using an Apple API, for example using PyObjC:

    from Foundation import NSUserDefaults
    defaults = NSUserDefaults.standardUserDefaults()
    globalDomain = defaults.persistentDomainForName_("NSGlobalDomain")
    languages = globalDomain.objectForKey_("AppleLanguages")

    On my system this returns:

    >>> print(languages)

    See also "".

    The advantage of getting the language information using the Apple API is that you can pick the first language from the list that you have a translation for.

  3. Log in to comment