cmiller8 cmiller8 - 1 year ago 63
Python Question

IPython Notebook locale error

After installing the latest Mac OSX 64-bit Anaconda Python distribution, I keep getting a ValueError when trying to start the IPython Notebook.

Starting ipython works fine:

Python 2.7.3 |Anaconda 1.4.0 (x86_64)| (default, Feb 25 2013, 18:45:56)
Type "copyright", "credits" or "license" for more information.

IPython 0.13.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.

But starting ipython notebook:

4-millerc-~:ipython notebook

Results in the ValueError (with traceback):

Traceback (most recent call last):
File "/Users/millerc/anaconda/bin/ipython", line 7, in <module>
File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/frontend/terminal/", line 388, in launch_new_instance
File "<string>", line 2, in initialize
File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/config/", line 84, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/frontend/terminal/", line 313, in initialize
super(TerminalIPythonApp, self).initialize(argv)
File "<string>", line 2, in initialize
File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/config/", line 84, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/core/", line 325, in initialize
File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/frontend/terminal/", line 308, in parse_command_line
return super(TerminalIPythonApp, self).parse_command_line(argv)
File "<string>", line 2, in parse_command_line
File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/config/", line 84, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/config/", line 420, in parse_command_line
return self.initialize_subcommand(subc, subargv)
File "<string>", line 2, in initialize_subcommand
File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/config/", line 84, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/config/", line 352, in initialize_subcommand
subapp = import_item(subapp)
File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/utils/", line 40, in import_item
module = __import__(package,fromlist=[obj])
File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/frontend/html/notebook/", line 46, in <module>
from .handlers import (LoginHandler, LogoutHandler,
File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/frontend/html/notebook/", line 36, in <module>
from docutils.core import publish_string
File "/Users/millerc/anaconda/lib/python2.7/site-packages/docutils/", line 20, in <module>
from docutils import frontend, io, utils, readers, writers
File "/Users/millerc/anaconda/lib/python2.7/site-packages/docutils/", line 41, in <module>
import docutils.utils
File "/Users/millerc/anaconda/lib/python2.7/site-packages/docutils/utils/", line 20, in <module>
from import FileOutput
File "/Users/millerc/anaconda/lib/python2.7/site-packages/docutils/", line 18, in <module>
from docutils.utils.error_reporting import locale_encoding, ErrorString, ErrorOutput
File "/Users/millerc/anaconda/lib/python2.7/site-packages/docutils/utils/", line 47, in <module>
locale_encoding = locale.getlocale()[1] or locale.getdefaultlocale()[1]
File "/Users/millerc/anaconda/lib/python2.7/", line 503, in getdefaultlocale
return _parse_localename(localename)
File "/Users/millerc/anaconda/lib/python2.7/", line 435, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

Running the
command from the terminal:


Answer Source

I summarize here the solution to be found on:

I added these lines to my .bash_profile:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

I reloaded the profile:

source ~/.bash_profile

I then ran ipython again:

ipython notebook

Changing locales

The above will work for the English language in a US locale. One may want different settings.

At the risk of stating the obvious, to discover the current settings for your system, use:

$ locale

And to retrieve a list of all valid settings on your system:

$ locale -a

Then choose your preferred locale. For example, for a Swiss French locale, the solution would look like this:

export LC_ALL=fr_CH.UTF-8
export LANG=fr_CH.UTF-8
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download