【问题标题】:Errors with matplotlib, what am I missing?matplotlib 错误,我错过了什么?
【发布时间】:2015-10-06 15:57:47
【问题描述】:

我一直在试验 SPy(光谱 Python),在 Mac 上使用 PyCharm。我一直在错误地遇到错误,但就目前而言,我完全被这个错误所困扰:

程序输出:

/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 "/Users/pkillam/PycharmProjects/untitled/SPy Experiments"
/Library/Python/2.7/site-packages/spectral/spectral.py:198: UserWarning: Unable to import or configure pylab plotter.  Spectrum plots will be unavailable.
  'will be unavailable.', UserWarning)

    .
    .    #normal output
    .

Traceback (most recent call last):
  File "/Users/pkillam/PycharmProjects/untitled/SPy Experiments", line 28, in <module>
    view = imshow(img, (29, 19, 9))
  File "/Library/Python/2.7/site-packages/spectral/graphics/spypylab.py", line 1238, in imshow
    import matplotlib.pyplot as plt
  File "/Library/Python/2.7/site-packages/matplotlib/pyplot.py", line 34, in <module>
    from matplotlib.figure import Figure, figaspect
  File "/Library/Python/2.7/site-packages/matplotlib/figure.py", line 40, in <module>
    from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
  File "/Library/Python/2.7/site-packages/matplotlib/axes/__init__.py", line 4, in <module>
    from ._subplots import *
  File "/Library/Python/2.7/site-packages/matplotlib/axes/_subplots.py", line 10, in <module>
    from matplotlib.axes._axes import Axes
  File "/Library/Python/2.7/site-packages/matplotlib/axes/_axes.py", line 21, in <module>
    import matplotlib.dates as _  # <-registers a date unit converter
  File "/Library/Python/2.7/site-packages/matplotlib/dates.py", line 126, in <module>
    from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY,
  File "/Library/Python/2.7/site-packages/dateutil/rrule.py", line 16, in <module>
    from six.moves import _thread
ImportError: cannot import name _thread

Process finished with exit code 1

这是代码,主要来自此处的 SPy 指南:http://www.spectralpython.net/user_guide.html

import matplotlib
matplotlib.use('WX')
from spectral import *

img = open_image('92AV3C.lan')
print img.__class__
print
print img
print
print img.shape
pixel = img[50,100]
print
print pixel.shape
band6 = img[:,:,5]
print
print band6.shape
print

arr = img.load()
print arr.__class__
print
print arr.info()
print
print arr.shape

view = imshow(img, (29, 19, 9))

有什么想法吗?

【问题讨论】:

  • 您的六版本可能太旧了。如果您使用的是 Mac,我强烈建议您使用 anaconda。在 mac 上安装 python 会非常非常痛苦。
  • 直到您需要 c 扩展。我从未见过有人在 Mac 上正确地从源代码安装完整的科学堆栈,我认识的每个人都使用 homebrew/macport/canopy/anaconda 的某种组合。
  • 还有一些持久性框架/非框架问题似乎让 gui 应用程序感到困惑
  • 参见matplotlib.org/faq/installing_faq.html#os-x-notes,它是特定于 mpl 的,但通常适用于整个科学堆栈。
  • 我很抱歉分散了你的谈话注意力,但我同意@tcaswell 的观点,我从未见过有人在从源代码安装时在 Mac 上很好地使用科学堆栈。 Anaconda 是一个很好的解决方案。然后安装SPy 只需执行pip install spectral。 Spectral 是纯 python,所以如果它不起作用,那将是令人惊讶的,但我只是尝试过,至少它是导入的。

标签: python matplotlib pycharm package spectral-python


【解决方案1】:

好的,我解决了这个问题。事实证明,自从我使用自己的包管理器更新 PyCharm 以来,PyCharm 一直在尝试访问两个不同版本的 matplotlib。我通过删除其中一个版本来解决此问题,但是,后来我继续遇到一个又一个问题。

这个代码现在完全可以工作了,因为我改用 Anaconda 的 Spyder 而不是 Pycharm,后者更容易使用!

感谢所有在 cmets 中提供帮助的人。

【讨论】:

    猜你喜欢
    • 2019-08-29
    • 2013-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    相关资源
    最近更新 更多