3

After updating IPython I constantly have problems with matplotlib. At the beginning of my notebook I have

%matplotlib inline
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import scipy
from qutip import *
import time

Which generate a screen full of issues but the final part is

/Users/murray/anaconda/lib/python2.7/locale.pyc in _parse_localename(localename)
    473     elif code == 'C':
    474         return None, None
--> 475     raise ValueError, 'unknown locale: %s' % localename
    476 
    477 def _build_localename(localetuple):

ValueError: unknown locale: UTF-8

There were other issues before this which I managed to fix. Similar things have been reported here but no solution which works for me. One solution I found online suggested running

export LANG="it_IT.UTF-8"

in the terminal window (plus about 8 other similar commands). This worked but everytime I restart the notebook I have to reenter all of this. As you might guess I am not an expert - I would assume there is a more permanent fix for this problem

Mike Müller
  • 82,630
  • 20
  • 166
  • 161
user3799584
  • 917
  • 1
  • 9
  • 18
  • @tcaswell - this is not the same error as the one you have linked to. In my case I could start the notebook and it was only when I run the cell as indicated. The one you have linked to could not even start the notebook. – user3799584 Mar 19 '16 at 04:04
  • It is the same issue, just being exposed through a slightly different path. Apple exports a non-standard locale setting that causes an exception to be raised from the python standard library `locale` module. In both cases the fix is to manually change the locale to one that the `locale` module can deal with. – tacaswell Mar 19 '16 at 04:21
  • Ok - but in looking for an answer to my question I would not read a post that started by saying the notebook wouldn't open. Same answer doesn't imply the same question. – user3799584 Mar 19 '16 at 04:46
  • Hence the value in marking this as a duplicate as the other question has two very good answers on how to fix the problem. – tacaswell Mar 19 '16 at 14:51

1 Answers1

1

As a work around, you can put export LANG="it_IT.UTF-8" and the "8 other similar commands" into your .profile (assuming your are on Mac OS X). At the end of this file /Users/murray/.profile write:

# Fix for matplotlib imports in IPython
export LANG="it_IT.UTF-8"
# your other 8 lines here without the # in front

You need to start a new terminal window. In there, start a new IPython session.

Mike Müller
  • 82,630
  • 20
  • 166
  • 161