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

[Mac OS X 10.10.5] Macports install error :unknown locale: UTF-8 #5420

Closed
src10 opened this issue Nov 6, 2015 · 19 comments

Comments

Projects
None yet
@src10
Copy link

commented Nov 6, 2015

Hi guys!
I am new to python and matplotlib.
I installed everything with macports and when I run the matplotlib test

python2.7 -c 'import matplotlib; print matplotlib.version, matplotlib.file'

I get the following

Traceback (most recent call last):
File "", line 1, in
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/init.py", line 1131, in
rcParams = rc_params()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/init.py", line 975, in rc_params
return rc_params_from_file(fname, fail_on_error)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/init.py", line 1100, in rc_params_from_file
config_from_file = _rc_params_in_file(fname, fail_on_error)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/init.py", line 1018, in _rc_params_in_file
with _open_file_or_url(fname) as fd:
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in enter
return self.gen.next()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/init.py", line 1000, in _open_file_or_url
encoding = locale.getdefaultlocale()[1]
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 543, in getdefaultlocale
return _parse_localename(localename)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 475, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

Do you guys have any idea what is happening....I have not done enything weards just follow simple steps to install it.

I want to use QUTIP and the matplotlib is essential for it...please if someone know it would be really nice

thanks!
regards,

@mdboom

This comment has been minimized.

Copy link
Member

commented Nov 6, 2015

Can you do:

› /usr/bin/python
Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'UTF-8')

If that doesn't work for you, it's something wrong in your environment. You may be hitting this bug

@src10

This comment has been minimized.

Copy link
Author

commented Nov 6, 2015

when I run

import locale
locale.getdefaultlocale()

I also get an error

Traceback (most recent call last):
File "", line 1, in
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 543, in getdefaultlocale
return _parse_localename(localename)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 475, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

Sorry to bother...how can I use the patch on the link...copy on terminal ? or run it on python

@mdboom

This comment has been minimized.

Copy link
Member

commented Nov 6, 2015

Unless you want to build your own Python (which I wouldn't recommend), I'd add this to your .bash_profile (assuming you use bash) and restart the shell.

export LANG=en_US.UTF-8

That's for "United States English". If you want something else, set your language and country code accordingly.

@mdboom mdboom closed this Nov 6, 2015

@src10

This comment has been minimized.

Copy link
Author

commented Nov 6, 2015

If I do this i dont get the error anymore!!..but now I can not do anything in the terminal....here are some examples
ipython
-bash: ipython: command not found
port search ipython
-bash: port: command not found
sudo port install py27-matplotlib
Password:
sudo: port: command not found

If I remove the .bash_profile everything works again but I get the original mistake

any ideas???

@mdboom

This comment has been minimized.

Copy link
Member

commented Nov 6, 2015

I guess that's overriding your entire bash configuration. (I use zsh, not bash, so I'm flying blind here). You could try using ~/.bashrc instead, or Google for how to set environment variables on bash on a Mac.

@motjuste

This comment has been minimized.

Copy link

commented Jan 26, 2016

I already had the suggested LANG variable in my zshrc file. But I still faced the problem.

I found that the problem was then coming from LC_CTYPE which was set to UTF-8, but I had done nothing related to it in my zshrc file. And I did not want to either.

As suggested in this blog post by someone, I disabled "set locale variables automatically" in iTerm.

No problems since then.

@shiningbridge

This comment has been minimized.

Copy link

commented Feb 15, 2016

@motjuste 's solution works for me. Thanks for the sharing. :)

@martinengebretsen

This comment has been minimized.

Copy link

commented Apr 17, 2016

I am having the exact same problem as src10. Being quite new to mac, I have NO IDEA how to implement the advice in the blog.

This is the current content of the .bash_profile:

Setting PATH for Python 3.5
The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH

added by Anaconda3 4.0.0 installer
export PATH="/Users/E/anaconda/bin:$PATH"

When I try using the jupyter notebook to import plotly or any other module for that matter, I get this error:
ValueError: unknown locale: UTF-8, If I try adding the proposed solution for this problem in the bash_profile, I end up where src10 was,

ipython
-bash: ipython: command not found
port search ipython
-bash: port: command not found
sudo port install py27-matplotlib
Password:
sudo: port: command not found

HELP?!

ee

@clacri

This comment has been minimized.

Copy link

commented Jul 9, 2016

yes, @motjuste 's solution also worked for me in El Capitan. @martinengebretsen , to apply the advice in the blog you just need to open a terminal in Mac, search in the Terminal menu, hit Preferences, and then, go to Advanced. There is a checkbox where it says "set locale environment variables on startup". You just have to uncheck it :)

@taushifkhan

This comment has been minimized.

Copy link

commented Aug 2, 2016

python on OSX El Capitan 10.11

  1. Reinstall python : brew reinstall python
  2. set local environment variable on startup (UNSELECT) : terminal --> Preference --> Advance
    bingo. all packages are installed and imported cleanly. 👍 @clacri @martinengebretsen
@tianqig

This comment has been minimized.

Copy link

commented Aug 16, 2016

@motjuste's solution not working for me, not sure why:=(. My python is 2.7.12
on OSX El Capitan 10.11

I did the two procedures above 1 and 2, but still got the same errors

Anyone can help? Thanks

@jenshnielsen

This comment has been minimized.

Copy link
Member

commented Aug 16, 2016

What happens if you do:

>>> import locale
>>> locale.getdefaultlocale()
@jenshnielsen

This comment has been minimized.

Copy link
Member

commented Aug 16, 2016

In addition we should have a work around for this in the next release so you can install the 2.0 beta. Assuming that you are using pip that would be

pip install matplotlib --pre
@tianqig

This comment has been minimized.

Copy link

commented Aug 16, 2016

@jenshnielsen, thanks for your suggestion.

the first import ok, the second import got the following errors:

locale.getdefaultlocale()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 545, in getdefaultlocale
return _parse_localename(localename)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 477, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

@jenshnielsen

This comment has been minimized.

Copy link
Member

commented Aug 16, 2016

Ok so it is indeed the usual problem. I had hoped that it was fixed in python 2.7.12. Anyway you should be able to fix it by setting the LANG environmental variable. If the following works

export LANG=en_US.UTF-8
python
>>> import locale
>>> locale.getdefaultlocale()

I suggest setting

export LANG=en_US.UTF-8

permanently in either .bash_profile or .bash_rc if you are using a bash shell

@tianqig

This comment has been minimized.

Copy link

commented Aug 16, 2016

@jenshnielsen

I added two lines in my .bash_profile
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

when import matplotlib, I got the same errors as before

Anything I can try ? Thanks

I also tried the above as you suggested:

export LANG=en_US.UTF-8
python

import locale
locale.getdefaultlocale()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 545, in getdefaultlocale
return _parse_localename(localename)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 477, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

@jenshnielsen

This comment has been minimized.

Copy link
Member

commented Aug 16, 2016

can you try unsetting LC_CTYPE? Which is what is used by default according to https://docs.python.org/2/library/locale.html#locale.getlocale

i.e.

export LANG=en_US.UTF-8
unset LC_CTYPE
python
>>> import locale
>>> locale.getdefaultlocale()
@tianqig

This comment has been minimized.

Copy link

commented Aug 16, 2016

Great! Thanks for your magic fix :=))

No more errors for above two cmd, also working for
import matplotlib

@kholmatov

This comment has been minimized.

Copy link

commented Sep 24, 2017

If you have faced the error on MacOS X, here's the quick fix - add these lines to your ~/.bash_profile:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.