New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
locale.getdefaultlocale() fails on OS X #5019
Conversation
For any reason ``locale.getdefaultlocale()`` fails on OS X (returns None), which subsequently produces errors and makes the ``matplotlib`` module unusable. Checking for a ``None`` result and then setting the default encoding to ``"utf-8"`` seems to help.
@@ -992,6 +992,8 @@ def _open_file_or_url(fname): | |||
else: | |||
fname = os.path.expanduser(fname) | |||
encoding = locale.getdefaultlocale()[1] | |||
if encoding == None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do equality when testing against None
. Do if encoding is None:
.
@mdehoon, does this fallback make sense to you? I don't know about system encodings on Macs. |
On my mac |
No idea, sorry. |
According to the Python documentation, the result of
So, |
@jheinen Thanks, you short cut my research on this which was going through https://bugs.python.org/issue18378 ! I am 👍 on merging this, but as the bug was reported specifically against OSX, one of the OSX-based devs should merge this. |
I am not an OSX expert by any means, but if no one else comments or merges it, I will do so within 24 hours. I don't see how it could hurt anything. |
On an old Mac I have that is running OS X 10.8, I think Microsoft Office 2008 still used Mac Roman by default, so there's at least a theoretical risk if you edited your matplotlibrc in Word 2008 and used non-ASCII characters for some values. But in any case, if passing |
Plenty of software is going to fail strangely if your locale doesn't match your files. I guess utf-8 is a reasonable default in 2015, but I also think it's the user's or sysadmin's responsibility to fix the configuration. |
I have a suggestion for a slightly better error message at jheinen#1. |
On a couple of 10.6 Macs I have: Mac 1: (None, None) for Pythons 2.5, 2.5, ('en_US', 'UTF-8') for Python 3.4.1 |
I think this is useful as is, so I'll merge it, and make a separate PR about the error message. |
Default to UTF-8 if locale.getdefaultlocale() returns None for the encoding
For any reason
locale.getdefaultlocale()
fails on OS X (returns None), which subsequently produces errors and makes thematplotlib
module unusable. Checking for aNone
result and then setting the default encoding to"utf-8"
seems to help.