导入错误:找不到matplotlib模块

8

几个月前,Matplotlib还能正常工作。但现在我不断收到以下错误:

ImportError: No module named matplotlib

我使用pip再次安装了matplotlib。但是它没有起作用。我尝试使用easyinstall,仍然无法正常工作。
使用pip进行安装会得到以下结果:
Requirement already satisfied (use --upgrade to upgrade): matplotlib in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib-1.5.0-py2.7-macosx-10.6-intel.egg
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.6 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/python_dateutil-2.4.2-py2.7.egg (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): pytz in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pytz-2015.7-py2.7.egg (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): cycler in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cycler-0.9.0-py2.7.egg (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): pyparsing!=2.0.0,!=2.0.4,>=1.5.6 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyparsing-2.0.6-py2.7.egg (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/six-1.10.0-py2.7.egg (from python-dateutil->matplotlib)

然后我使用了

sudo -E pip install matplotlib --upgrade

之后,我得到了...
The directory '/Users/ruskin/Library/Logs/pip' or its parent directory is not owned by the current user and the debug log has been disabled.        Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/ruskin/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled.   Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
You are using pip version 6.1.1, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The directory '/Users/ruskin/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

它继续升级matplotlib,但最终我得到了以下结果:
Requirement already up-to-date: python-dateutil in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/python_dateutil-2.4.2-py2.7.egg (from matplotlib)
Requirement already up-to-date: pytz in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pytz-2015.7-py2.7.egg (from matplotlib)
Requirement already up-to-date: cycler in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cycler-0.9.0-py2.7.egg (from matplotlib)
Requirement already up-to-date: pyparsing!=2.0.0,!=2.0.4,>=1.5.6 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyparsing-2.0.6-py2.7.egg (from matplotlib)
Requirement already up-to-date: six>=1.5 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/six-1.10.0-py2.7.egg (from python-dateutil->matplotlib)
Installing collected packages: numpy
  Found existing installation: numpy 1.9.1
 Uninstalling numpy-1.9.1:
  Exception:
  Traceback (most recent call last):
    File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 246, in main
      status = self.run(options, args)
    File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 352, in run
      root=options.root_path,
    File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 687, in install
      requirement.uninstall(auto_confirm=True)
    File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 730, in uninstall
      paths_to_remove.remove(auto_confirm)
    File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 126, in remove
      renames(path, new_path)
    File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 292, in renames
      shutil.move(old, new)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 303, in move
      os.unlink(src)
  OSError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy-1.9.1.dist-info/DESCRIPTION.rst'

2
检查你的 which python 路径。 - JRodDynamite
阅读此问题的答案:Pip Install未安装到正确目录? - k4ppa
@JasonEstibeiro /Library/Frameworks/Python.framework/Versions/2.7/bin/python 我认为这是好的。 - ruskin23
@PeterWood 我使用了sudo -E pip install matplotlib --upgrade,然后出现了以下提示:DEPRECATION: 卸载distutils安装的项目(numpy)已被弃用,并将在未来版本中删除。这是因为卸载distutils项目只会部分卸载该项目。接着,我尝试卸载numpy-1.8.0rc1时出现了以下异常: Exception: Traceback (most recent call last): File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 246, in main status = self.run(options, args) - ruskin23
brew install matplotlib - Pavleg
显示剩余4条评论
1个回答

4
在 OS X 操作系统中,不要以根用户身份安装 Python 模块,这会导致无尽的失败。使用 --user 参数为当前用户安装模块,例如:pip 命令。
localhost:~ sorins$ which python
/usr/local/bin/python

python -m pip install --user --upgrade matplotlib

此外,请确保您正在使用正确的Python解释器,因为Pip经常会混淆并安装模块到不包含在Python PATH(sys.path)中的位置。

这个问题的完美解决方案!花了一个多小时来修复,直到最终在你的帮助下解决了它。 - Kevin Katzke

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接