mac笔记本安装matplotlib后,导入模块时报错

>>> import matplotlib.pyplot as pl
/Users/wang/.virtualenvs/ml/lib/python2.7/site-packages/matplotlib/__init__.py:1074: UserWarning: Cannot decode configuration file /Users/wang/.matplotlib/matplotlibrc with encoding US-ASCII, check LANG and LC_* variables
  'utf-8 (default)'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/wang/.virtualenvs/ml/lib/python2.7/site-packages/matplotlib/__init__.py", line 1163, in <module>
    rcParams = rc_params()
  File "/Users/wang/.virtualenvs/ml/lib/python2.7/site-packages/matplotlib/__init__.py", line 1007, in rc_params
    return rc_params_from_file(fname, fail_on_error)
  File "/Users/wang/.virtualenvs/ml/lib/python2.7/site-packages/matplotlib/__init__.py", line 1134, in rc_params_from_file
    config_from_file = _rc_params_in_file(fname, fail_on_error)
  File "/Users/wang/.virtualenvs/ml/lib/python2.7/site-packages/matplotlib/__init__.py", line 1052, in _rc_params_in_file
    for line in fd:
  File "/Users/wang/.virtualenvs/ml/lib/python2.7/encodings/ascii.py", line 27, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 10: ordinal not in range(128)

------------------------------------------------------------------------------------------------------------------------------------------------------
#使用pip install matplotlib安装
$ pip list
cycler (0.10.0)
functools32 (3.2.3.post2)
kiwisolver (1.0.1)
numpy (1.14.2)
pandas (0.22.0)
pip (9.0.1)
pyparsing (2.2.0)
python-dateutil (2.7.0)
pytz (2018.3)
scikit-learn (0.19.1)
scipy (1.0.0)
setuptools (39.0.0)
six (1.11.0)
subprocess32 (3.2.7)
wheel (0.30.0)

#python安装目录
$ which python
/Users/wang/.virtualenvs/ml/bin/python

搞了好长时间都没解决,不太明白是什么原因,请老师帮忙解决下

Robin_TY - PhD@CSU,研究方向:计算机视觉,模式识别

赞同来自:

在python的安装目录下有不能被ascii编码的字符,可能是中文。 看了你的错误信息,使用的是python2.7,可以换成python3试试。

fisha9w

赞同来自:

/Users/wang/.virtualenvs/ml/  这个目录没有中文啊 python3我试过了 也报同样的错

fisha9w

赞同来自:

(env34) wangdeMacBook-Pro:~ wang$ python Python 3.4.5 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:47:57) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import matplotlib.pyplot as pl /Users/wang/.virtualenvs/env34/lib/python3.4/site-packages/matplotlib/__init__.py:1074: UserWarning: Cannot decode configuration file /Users/wang/.matplotlib/matplotlibrc with encoding US-ASCII, check LANG and LC_* variables   'utf-8 (default)')) Traceback (most recent call last):   File "<stdin>", line 1, in <module>   File "/Users/wang/.virtualenvs/env34/lib/python3.4/site-packages/matplotlib/__init__.py", line 1163, in <module>     rcParams = rc_params()   File "/Users/wang/.virtualenvs/env34/lib/python3.4/site-packages/matplotlib/__init__.py", line 1007, in rc_params     return rc_params_from_file(fname, fail_on_error)   File "/Users/wang/.virtualenvs/env34/lib/python3.4/site-packages/matplotlib/__init__.py", line 1134, in rc_params_from_file     config_from_file = _rc_params_in_file(fname, fail_on_error)   File "/Users/wang/.virtualenvs/env34/lib/python3.4/site-packages/matplotlib/__init__.py", line 1052, in _rc_params_in_file     for line in fd:   File "/Users/wang/.virtualenvs/env34/lib/python3.4/encodings/ascii.py", line 26, in decode     return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 10: ordinal not in range(128)

Robin_TY - PhD@CSU,研究方向:计算机视觉,模式识别

赞同来自:

没遇到过。。。可以试试py3.5以上的版本。 matplotlib是额外安装的,还是和anaconda里带的? 如果是额外安装的话,建议安装anaconda。

要回复问题请先登录注册