diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 3c7e1c923f14..b0eadc8cd867 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1002,7 +1002,7 @@ def _open_file_or_url(fname): f.close() else: fname = os.path.expanduser(fname) - encoding = locale.getdefaultlocale()[1] + encoding = locale.getpreferredencoding(do_setlocale=False) if encoding is None: encoding = "utf-8" with io.open(fname, encoding=encoding) as f: @@ -1043,7 +1043,8 @@ def _rc_params_in_file(fname, fail_on_error=False): warnings.warn( ('Cannot decode configuration file %s with ' 'encoding %s, check LANG and LC_* variables') - % (fname, locale.getdefaultlocale()[1] or 'utf-8 (default)')) + % (fname, locale.getpreferredencoding(do_setlocale=False) or + 'utf-8 (default)')) raise config = RcParams()