2016-06-09 88 views
0

我想在Mac(10.7.5 Lion)中安裝Matplotlib,其中python(2.7.1),pip(8.1.2),numpy(1.11.0),astropy(1.2)已經安裝並正在工作如預期。首先,我試着用命令安裝Matplotlib

sudo pip install matpltlib 

,它表明Matplotlib 1.5.1已成功安裝。但是,當我進入蟒蛇和類型import matplotlib這表明這樣的錯誤消息:

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/Library/Python/2.7/site-packages/matplotlib/__init__.py", line 1131, in <module> 
    rcParams = rc_params() 
    File "/Library/Python/2.7/site-packages/matplotlib/__init__.py", line 975, in rc_params 
    return rc_params_from_file(fname, fail_on_error) 
    File "/Library/Python/2.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 "/Library/Python/2.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 "/Library/Python/2.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 496, in getdefaultlocale 
    return _parse_localename(localename) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 428, in _parse_localename 
    raise ValueError, 'unknown locale: %s' % localename 
ValueError: unknown locale: UTF-8 

我不明白,究竟是什麼問題。我打開了所有這些.py文件,並且已經讀取了指定行中的命令。由於這些是隻讀文件(甚至是根目錄),因此無法編輯任何內容。我不知道如何解決這個問題。

好吧,我再由PIP卸載它,並試圖從source.When安裝我嘗試(下載280 MB的源文件後)通過python setup.py build打造它,它最終將幾個錯誤,如這個 -

src/_macosx.m:2494: warning: implicit conversion shortens 64-bit value into a 32-bit value 
src/_macosx.m:1337: error: ‘for’ loop initial declaration used outside C99 mode 
lipo: can't open input file: /var/folders/ks/31hhg2hj3273tbk2xwbjfv2h0000gn/T//ccEOsZZ4.out (No such file or directory) 
lipo: can't open input file: /var/tmp//ccLauouU.out (No such file or directory) 
error: command 'llvm-gcc-4.2' failed with exit status 1 

我查過了,沒有名爲var的目錄。我無法調試這個了。

+0

命令'locale'(在你的終端中,不是Python)產生了什麼?您似乎具有無效的區域設置配置。 –

+0

它產生 「LANG = LC_COLLATE =」 C 「 LC_CTYPE = 」UTF-8「 LC_MESSAGES = 」C「 LC_MONETARY = 」C「 LC_NUMERIC = 」C「 LC_TIME = 」C「 LC_ALL = 」 – Sanskriti

+0

注意你的'LC_CTYPE'變量;應該將語言環境變量設置爲語言代碼,再加上一個點和一個字符集。將它設置爲'LC_CTYPE =「en_US.UTF-8」';你可能想找到它的位置。 –

回答

0

您錯誤地配置了您的語言環境; matplotlib似乎已正確安裝,但在導入時調用locale.getdefaultlocale() function

該函數試圖從'LANGUAGE','LC_ALL','LC_CTYPE''LANG'環境變量中確定您當前的語言環境。其中至少有一個未設置爲語言代碼加編碼;你有它設置爲編碼只有

使用locale命令查看當前設置是什麼。任何目前設置爲只是UTF-8設置不正確,缺少語言代碼(如en_USen_GBes_ES等)。您通常應該將設置區域設置變量保留到您的OS X終端;看到https://apple.stackexchange.com/questions/21096/where-does-lang-variable-gets-set-in-mac-os-x

檢查~/.profile也許~/.bashrc文件上看到錯誤的變量被設置和刪除這一行,或者至少是增加一個語言代碼給它,用點分隔。