diff -r eee959fee5f5 Lib/_bootlocale.py --- a/Lib/_bootlocale.py Sat May 07 21:13:50 2016 +0300 +++ b/Lib/_bootlocale.py Sat May 21 10:48:27 2016 +0200 @@ -15,6 +15,13 @@ _locale.CODESET except AttributeError: def getpreferredencoding(do_setlocale=True): + # Avoid importing locale and its dependencies when none of the + # locale environment variables is set. + import os + if (set(os.environ).isdisjoint(('LC_ALL', 'LC_CTYPE', 'LANG', + 'LANGUAGE'))): + return 'ascii' + # This path for legacy systems needs the more complex # getdefaultlocale() function, import the full locale module. import locale