我一直在Mac上使用PyCharm进行SPy(Spectral Python)的实验。我一直遇到一个接一个的错误,但就目前情况而言,它完全被我绊倒了:
程序输出:
/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))
有什么想法吗?
好,我解决了这个问题。事实证明,自从我使用自己的软件包管理器对其进行更新以来,PyCharm就一直试图访问两个不同版本的matplotlib。我通过删除其中一个版本来解决此问题,但是后来我继续遇到问题。
此代码现在可以完全正常工作,因为我移到了Anaconda的Spyder而不是Pycharm,它使用起来非常容易得多!
谢谢您,所有在评论中提供帮助的人。