4

I run the python script that contain Pandas (that one cause the problem) library I got this error:

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    import pandas
ImportError: No module named pandas

But if I import from package path to make sure it detects Pandas library, I got this error message

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    import pandas
  File "/usr/local/lib/python2.7/site-packages/pandas/__init__.py", line 44, in <module>
    from pandas.core.api import *
  File "/usr/local/lib/python2.7/site-packages/pandas/core/api.py", line 9, in <module>
    from pandas.core.groupby import Grouper
  File "/usr/local/lib/python2.7/site-packages/pandas/core/groupby.py", line 16, in <module>
    from pandas.core.frame import DataFrame
  File "/usr/local/lib/python2.7/site-packages/pandas/core/frame.py", line 41, in <module>
    from pandas.core.series import Series
  File "/usr/local/lib/python2.7/site-packages/pandas/core/series.py", line 2864, in <module>
    import pandas.tools.plotting as _gfx
  File "/usr/local/lib/python2.7/site-packages/pandas/tools/plotting.py", line 28, in <module>
    import pandas.tseries.converter as conv
  File "/usr/local/lib/python2.7/site-packages/pandas/tseries/converter.py", line 7, in <module>
    import matplotlib.units as units
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1131, in <module>
    rcParams = rc_params()
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 975, in rc_params
    return rc_params_from_file(fname, fail_on_error)
  File "/usr/local/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 "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1018, in _rc_params_in_file
    with _open_file_or_url(fname) as fd:
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1000, in _open_file_or_url
    encoding = locale.getdefaultlocale()[1]
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 543, in getdefaultlocale
    return _parse_localename(localename)
  File "/System/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

I already update my .bash_profile and .bashrc with these lines but still not working even I already restart the terminal and my machine.

export LANG="it_IT.UTF-8"  
export LC_COLLATE="it_IT.UTF-8"  
export LC_CTYPE="it_IT.UTF-8"  
export LC_MESSAGES="it_IT.UTF-8"  
export LC_MONETARY="it_IT.UTF-8"  
export LC_NUMERIC="it_IT.UTF-8"  
export LC_TIME="it_IT.UTF-8"  
export LC_ALL="it_IT.UTF-8"

I'm also enabled Set locale environment variables on startup in the terminal preferences.

enter image description here

I'm afraid the problem caused because of El Capitan.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nurdin
  • 23,382
  • 43
  • 130
  • 308
  • This has nothing to do with your terminal encoding, which only affects the display of text stream in the terminal. – 4ae1e1 Nov 15 '15 at 05:33
  • I need to fix this. It will affect my result. – Nurdin Nov 15 '15 at 05:47
  • I don't think this is a duplicate question because set LC_ALL doesn't work for me. The solution works for me is to uncheck the Set locale env variables on startup at terminal's preferences. – hsc May 05 '16 at 15:36

1 Answers1

5

Edit: Pandas, and its dependencies, had localization bugs that were discovered in non-C locales and fixed in recent versions.

When I downloaded the latest version of Pandas onto an OS X Yosemite computer via sudo pip install pandas in a terminal set to it_IT.UTF-8, and then imported it in a new Python session, I wasn't able to reproduce this issue.

My best guess now - and I'd emphasize this is only a guess - is that the version of Pandas in that folder predates those fixes and is broken in it_IT.UTF-8. (I do think this is, on balance, more likely than the issue being specific to El Capitan.)


Your LC_ALL= is unset. That seems unusual; based on other answers here I think you should try setting it to LC_ALL="it_IT.UTF-8" and remove the other LC_ settings.

Then save your .bash_profile, open a new terminal tab, and try again.

Community
  • 1
  • 1
Will Angley
  • 1,392
  • 7
  • 11
  • 2
    You actually contradict yourself... You probably meant `LC_ALL="it_IT.UTF-8"` in the code block. – 4ae1e1 Nov 15 '15 at 05:35
  • Oops! Fixed now, thank you! – Will Angley Nov 15 '15 at 05:36
  • 1
    `LC_ALL` is _not_ normally set on OS X, but `LANG` is. You'd only need to set `LC_ALL` to override if someone else - unusually - had set `LC_ALL` too. Your `LC_ALL=...` command effectively overrides your `LANG=...` command - there is never a need for _both_. – mklement0 Nov 15 '15 at 05:42
  • I already update .bash_profile and restart my terminal. But it still happen. Same error message. – Nurdin Nov 15 '15 at 05:44
  • 1
    To back up @mklement0's claim: `man locale`. – 4ae1e1 Nov 15 '15 at 05:46
  • 1
    Browsed through `man locale`, and I understand I'm wrong here. This wouldn't change anything over OP's original locale settings. – Will Angley Nov 15 '15 at 05:56