python3.6中导入matplotlib的问题

时间:2017-04-19 08:47:46

标签: python opencv matplotlib

我正在尝试学习与road_lane_line_detection相关的项目。但是,除了“matplotlib”之外的其他依赖项已经成功安装,包括:numpy,opencv-python,moviepy。

这是录音:

(hqs0) ForddeMacBook-Pro:~ Ford$ pip install matplotlib
Requirement already satisfied: matplotlib in ./hqs0/lib/python3.6/site-packages
Requirement already satisfied: cycler>=0.10 in ./hqs0/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: python-dateutil in ./hqs0/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: pyparsing!=2.0.0,!=2.0.4,!=2.1.2,!=2.1.6,>=1.5.6 in ./hqs0/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: pytz in ./hqs0/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: numpy>=1.7.1 in ./hqs0/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: six>=1.10 in ./hqs0/lib/python3.6/site-packages (from matplotlib)
(hqs0) ForddeMacBook-Pro:~ Ford$ python
Python 3.6.1 (default, Apr  4 2017, 09:36:47) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import cv2
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/Ford/hqs0/lib/python3.6/site-packages/matplotlib/__init__.py", line 1182, in <module>
    rcParams = rc_params()
  File "/Users/Ford/hqs0/lib/python3.6/site-packages/matplotlib/__init__.py", line 1025, in rc_params
    return rc_params_from_file(fname, fail_on_error)
  File "/Users/Ford/hqs0/lib/python3.6/site-packages/matplotlib/__init__.py", line 1151, in rc_params_from_file
    config_from_file = _rc_params_in_file(fname, fail_on_error)
  File "/Users/Ford/hqs0/lib/python3.6/site-packages/matplotlib/__init__.py", line 1068, in _rc_params_in_file
    with _open_file_or_url(fname) as fd:
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 82, in __enter__
    return next(self.gen)
  File "/Users/Ford/hqs0/lib/python3.6/site-packages/matplotlib/__init__.py", line 1053, in _open_file_or_url
    with io.open(fname, encoding=encoding) as f:
IsADirectoryError: [Errno 21] Is a directory: '/Users/Ford/.matplotlib/matplotlibrc'
>>> 

我不确定为什么会导致这个问题,谢谢你的帮助或建议。

1 个答案:

答案 0 :(得分:0)

matplotlib使用名为matplotlibrc的文件来存储配置默认值。如果此文件存在,则安装脚本将尝试读取它。该错误告诉您/Users/Ford/.matplotlib/matplotlibrc确实存在,但它是一个目录而不是一个文件,这使设置脚本感到困惑。

您可以通过删除matplotlibrc目录来解决此问题,但请注意,其中没有任何重要文件。为安全起见,您可以将其重命名为其他内容:

mv /Users/Ford/.matplotlib/matplotlibrc /Users/Ford/.matplotlib/matploblirc_old