Skip to content
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

use locale.getpreferredencoding() to prevent OS X locale issues #5931

Merged
merged 1 commit into from
Feb 15, 2016
Merged

use locale.getpreferredencoding() to prevent OS X locale issues #5931

merged 1 commit into from
Feb 15, 2016

Conversation

ntessore
Copy link

There is an issue on OS X when the locale is set to UTF-8 (no language), which happens out of the box on some systems. This has been reported before in #3870 and #5481. Such a locale cannot be parsed by Python's locale.getdefaultlocale(), which will throw

ValueError: unknown locale: UTF-8

when importing matplotlib.

Python issue 18378 deals with this matter. There you will find the suggestion that a project should use locale.getpreferredencoding() over locale.getdefaultlocale()[1], which coincidentally also fixes the issue on OS X. The PR implements this change.

@jenshnielsen
Copy link
Member

Thanks that is probably the right way to go. I think we can set do_setlocale to false to make it safer see the python docs

@jenshnielsen jenshnielsen added this to the 1.5.2 (Critical bug fix release) milestone Jan 28, 2016
@ntessore
Copy link
Author

@jenshnielsen I wasn't sure about that flag, have put it in now.

tacaswell added a commit that referenced this pull request Feb 15, 2016
use `locale.getpreferredencoding()` to prevent OS X locale issues
@tacaswell tacaswell merged commit 8e38a54 into matplotlib:master Feb 15, 2016
tacaswell added a commit that referenced this pull request Feb 15, 2016
use `locale.getpreferredencoding()` to prevent OS X locale issues
@tacaswell
Copy link
Member

Backported to 1.5.x as 2ac494f

@ntessore ntessore deleted the patch-1 branch February 15, 2016 20:55
tacaswell added a commit to tacaswell/matplotlib that referenced this pull request May 22, 2016
use `locale.getpreferredencoding()` to prevent OS X locale issues
@mangolzy
Copy link

with numpy 1.11.2 and update my matplotlib to 1.5.1, and the change of setting in ~/.bash_profile, I find no problem in bash shell.
But, the error still exist when I use ipython, could anybody kindly tell what should be set before I can successfully import matplotlib in Ipython? ( i can't understand this suggestion : a project should use locale.getpreferredencoding() over locale.getdefaultlocale()[1] since i don't use locale.getdefaultlocale()[1] at all...where to be replaced?)
thank you!

@jenshnielsen
Copy link
Member

The change to local is within Matplotlib. This has been implemented in Matplotlib 1.5.2 so the easiest is to upgrade. It's also been fixed in OSX 10.12 as far as I know (this is really a bug in OSX) and a work around has been added to python to 2.7.12 and 3.5.2 as far as I know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants