1

I've been experimenting with SPy (Spectral Python), using PyCharm on a Mac. I've been running into error after error, but as it stands, its this error I'm completely stumped on:

Program Output:

/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

And here is the code, mostly from the SPy guide found here: 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))

Any ideas?

bogatron
  • 18,639
  • 6
  • 53
  • 47
NGXII
  • 407
  • 2
  • 9
  • 18
  • 2
    Your version of six is probably too old. If you are on a mac I strongly suggest using anaconda. Installing python on macs can be very very painful. – tacaswell Jul 17 '15 at 01:44
  • @tcaswell what's so painful about it? Download the installer from python.org, run it, adjust your path to point to the correct directories, and you're good to go. No difficulties at all if you know a little bit about the command line... – MattDMo Jul 17 '15 at 01:48
  • 1
    Until you need c-extensions. I have never seen anyone correctly install the full scientific stack from source on a mac, everyone I know uses some combination of homebrew/macport/canopy/anaconda. – tacaswell Jul 17 '15 at 01:56
  • 1
    And there are the persistent framework/not framework issues that seem to confuse gui applications – tacaswell Jul 17 '15 at 01:57
  • @tcaswell my version of six is up to date, and yeah, working with python in this mac has been very painful, 80% of my errors and 95% of my time trying to learn python and create projects has been dealing with errors related to packages and compatibility, which are in all likelihood caused in part by the fact I'm using a Mac. what exactly is anaconda, and will it play nice with PyCharm? I would prefer to not make too many changes to my setup, its barely working as it is... – NGXII Jul 17 '15 at 01:59
  • 1
    See http://matplotlib.org/faq/installing_faq.html#os-x-notes which is mpl specific, but applies generally across the scientific stack. – tacaswell Jul 17 '15 at 02:01
  • @tcaswell I tried out anaconda, and it does not support SPy natively, and I'd much rather not start all this running around again with a new IDE. I feel like we've gotten a bit off topic, any ideas on how to fix this error, or what caused it? – NGXII Jul 17 '15 at 02:18
  • 1
    see http://stackoverflow.com/questions/27630114/matplotlib-issue-on-os-x-importerror-cannot-import-name-thread maybe? – tacaswell Jul 17 '15 at 02:19
  • @tcaswell Awesome! That worked, thanks! Now its back to the error I got before, which I already opened a support ticket for... http://stackoverflow.com/questions/31466411/how-to-install-wxversion-for-python?noredirect=1#comment50899051_31466411 I just noticed you two were also the ones to comment there, keep being awesome! x3 Thanks for putting up with me. – NGXII Jul 17 '15 at 02:44
  • 4
    I apologize for distracting from your conversation, but I'd agree with @tcaswell that I've never seen anyone work well with the scientific stack on a Mac when installing from source. Anaconda is a great solution. Then to install `SPy` just do `pip install spectral`. Spectral is pure python so it would be surprising if it didn't work, but I just tried and at least it imports. – tom10 Jul 17 '15 at 02:52
  • @tom10 Where do I put that command? I'm still really new to python and how its structured, as well as using the command interface on a mac.. – NGXII Jul 17 '15 at 02:57
  • Yes, at the command line interface (eg, using the "Terminal.app" in your Mac utilities folder). When Anaconda installs, it will set common python commands like `pip`, `python`, `ipython`, etc, to the anaconda versions, so just `pip install spectral` will update your anaconda installation with `spectral`. – tom10 Jul 17 '15 at 03:04

1 Answers1

0

Alright, I fixed the problem. Turns out PyCharm was trying to access two different versions of matplotlib ever since I updated it using its own package manager. I fixed this by removing one of the versions, however, later on I continued running into problem after problem.

This code now works completely though, because I moved over to Anaconda's Spyder instead of Pycharm, which has been much, much easier to work with!

Thank you, everyone who helped in the comments.

NGXII
  • 407
  • 2
  • 9
  • 18