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

Merged
merged 1 commit into from Feb 15, 2016

Conversation

Projects
None yet
6 participants
Contributor

ntessore commented Jan 28, 2016

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.

mdboom added the needs_review label Jan 28, 2016

Owner

jenshnielsen commented Jan 28, 2016

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

Contributor

ntessore commented Jan 28, 2016

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

@ntessore ntessore use `locale.getpreferredencoding()`
cbac714

@tacaswell tacaswell added a commit that referenced this pull request Feb 15, 2016

@tacaswell tacaswell Merge pull request #5931 from ntessore/patch-1
use `locale.getpreferredencoding()` to prevent OS X locale issues
8e38a54

@tacaswell tacaswell merged commit 8e38a54 into matplotlib:master Feb 15, 2016

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

tacaswell removed the needs_review label Feb 15, 2016

@tacaswell tacaswell added a commit that referenced this pull request Feb 15, 2016

@tacaswell tacaswell Merge pull request #5931 from ntessore/patch-1
use `locale.getpreferredencoding()` to prevent OS X locale issues
2ac494f
Owner

tacaswell commented Feb 15, 2016

Backported to 1.5.x as 2ac494f

ntessore deleted the unknown repository branch Feb 15, 2016

This fix works for my julia 0.5-dev. After changing the source it no longer produces the error of locale utf-8!!

Thank you!

@tacaswell tacaswell added a commit to tacaswell/matplotlib that referenced this pull request May 22, 2016

@tacaswell tacaswell Merge pull request #5931 from ntessore/patch-1
use `locale.getpreferredencoding()` to prevent OS X locale issues
49f0dee

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!

Owner

jenshnielsen commented Nov 22, 2016

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