【问题标题】:Unable to import matplotlib.animation无法导入 matplotlib.animation
【发布时间】:2016-10-25 07:00:10
【问题描述】:

我是 python 和 OSX 的新手,所以如果我不了解超基本的东西,请原谅我。

我正在使用来自 Homebrew 的全新安装的 python 2.7.12。我还使用 Homebrew 安装 ipython、ffmpeg 和 libav(安装 avconv,我认为这是我想要做的事情所必需的)。

  • 我使用 pip 安装了 Scipy、numpy(我认为还是 scipy 自带的?)和 matplotlib
  • 我正在运行 El Capitan v10.11.6

背景(在某些情况下): 我正在运行一些输出一堆二进制文件的流体动力学模拟。我不想将它们拼接在一起制作电影。幸运的是,我的一位同事已经为此编写了一个整洁的小 Python 脚本(他用 ipython 编写)。

问题: 尝试运行时

import matplotlib.animation

脚本只是挂起,matplotlib 动画永远不会被导入。我尝试通过

更改后端
import matplotlib
matplotlib.use('tkagg')
import matplotlib.animaton

我尝试了通过运行List of all available matplotlib backends 的代码获得的各种后端

我也试过import matplotlib.pyplot hangs(更新fc-lists)

最后,我不确定这是否有帮助,但让 ipython 尝试导入 matplot.animation 大约 10 分钟,然后终止它输出以下内容

In [3]: import matplotlib.animation
^C---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-3-64e90e455a86> in <module>()
----> 1 import matplotlib.animation

/usr/local/lib/python2.7/site-packages/matplotlib/animation.py in <module>()
    589
    590 @writers.register('imagemagick')
--> 591 class ImageMagickWriter(MovieWriter, ImageMagickBase):
    592     def _args(self):
    593         return ([self.bin_path(),

/usr/local/lib/python2.7/site-packages/matplotlib/animation.py in wrapper(writerClass)
     73     def register(self, name):
     74         def wrapper(writerClass):
---> 75             if writerClass.isAvailable():
     76                 self.avail[name] = writerClass
     77             return writerClass

/usr/local/lib/python2.7/site-packages/matplotlib/animation.py in isAvailable(cls)
    284                              stderr=subprocess.PIPE,
    285                                      creationflags=subprocess_creation_flags)
--> 286             p.communicate()
    287             return True
    288         except OSError:

    /usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/ lib/python2.7/subprocess.pyc in communicate(self, input)
    798             return (stdout, stderr)
    799
--> 800         return self._communicate(input)
    801
    802

    /usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.pyc in _communicate(self, input)
   1417                 stdout, stderr =     self._communicate_with_poll(input)
   1418             else:
-> 1419                 stdout, stderr =     self._communicate_with_select(input)
   1420
   1421             # All data exchanged.  Translate lists into strings.

/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.pyc in _communicate_with_select(self, input)
   1518             while read_set or write_set:
   1519                 try:
-> 1520                     rlist, wlist, xlist =     select.select(read_set, write_set, [])
   1521                 except select.error, e:
   1522                     if e.args[0] == errno.EINTR:

KeyboardInterrupt:

如果您再考虑一下,即使您无法提供帮助,也非常感谢您!

【问题讨论】:

  • 您使用了哪些命令来安装插件?如果从脚本运行 if 与从提示符运行它一样,是否得到相同的结果?
  • 插件是指matplotlib等吗?我用 pip 来安装这些。例如,点安装 matplotlib。是的,如果我通过导航到文件夹并执行 python script.py 来运行脚本,它会像通过 ipython 一样挂在导入行上,或者如果我只是在提示符中输入它
  • 您使用的是虚拟环境吗?或者你需要做sudo pip install ...?另外,你试过普通的python吗? IE。不是 ipython。
  • 另外,你能用pip freeze的结果编辑你的问题吗?

标签: python animation matplotlib


【解决方案1】:

您是否安装了多个版本的 Python?我会检查你的 python 路径。在这种情况下,请确保 matplotlib 是 2.7。

这也可能是相关的——import matplotlib.pyplot hangs

【讨论】:

  • 感谢您的回复。当我最初遇到这个问题时,我也通过 anaconda2 安装了 python。我已经通过使用 conda-clean 'thing' (docs.continuum.io/anaconda/install#os-x-uninstall) 删除了它。我的python路径如下:PYTHONPATH=~/usr/local/lib/python2.7:$PYTHONPATH
  • 之后导出 PYTHONPATH
  • 看来我的 PATH 和 PYTHONPATH 可能有问题(我使用的语法不正确)。
  • 过去我在 anaconda 上遇到过类似的问题。那么问题解决了吗?
  • 有点(抱歉回复晚了)如果我希望能够使用 python script.py 运行我的脚本,我必须将我的 PYTHON 更改为 /usr/bin/python2.7。然后我遇到了无法使用 ipython 的问题(因为我已经通过自制软件安装了 ipython)。到目前为止,我还没有找到更永久的修复方法
猜你喜欢
  • 1970-01-01
  • 2021-11-20
  • 2017-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-31
相关资源
最近更新 更多