Python Using Py2exe (IndexError: list index out of range)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chriskim
    New Member
    • Jul 2010
    • 5

    Python Using Py2exe (IndexError: list index out of range)

    I wrote a program that uses PyQt4, mathplotlib to
    generates graphs. I made a executable file using Py2exe.

    Everything is working fine, but when I exit from my
    program, a window message pops out and tells me to look
    at the log file. In the log file, here is what they said

    C:\Users\dmckin non\Desktop\Chr isKim\eSimulato r_original\src\ dist\library.zi p\matplotlib\__ init__.py:572: UserWarning: Could not find matplotlibrc; using defaults
    C:\Users\dmckin non\Desktop\Chr isKim\eSimulato r_original\src\ dist\library.zi p\matplotlib\__ init__.py:633: UserWarning: could not find rc file; returning defaults
    Traceback (most recent call last):
    File "Epages.pyc ", line 305, in refractorySimul ation
    IndexError: list index out of range
    Traceback (most recent call last):
    File "Epages.pyc ", line 305, in refractorySimul ation
    IndexError: list index out of range
    Traceback (most recent call last):
    File "Epages.pyc ", line 305, in refractorySimul ation
    IndexError: list index out of range
    Traceback (most recent call last):
    File "Epages.pyc ", line 305, in refractorySimul ation
    IndexError: list index out of range
    Traceback (most recent call last):
    File "Epages.pyc ", line 305, in refractorySimul ation
    IndexError: list index out of range
    Traceback (most recent call last):
    File "Epages.pyc ", line 277, in thresholdSimula tion
    IndexError: list index out of range
    C:\Users\dmckin non\Desktop\Chr isKim\eSimulato r_original\src\ dist\library.zi p\matplotlib\__ init__.py:572: UserWarning: Could not find matplotlibrc; using defaults
    C:\Users\dmckin non\Desktop\Chr isKim\eSimulato r_original\src\ dist\library.zi p\matplotlib\__ init__.py:633: UserWarning: could not find rc file; returning defaults
    C:\Users\dmckin non\Desktop\Chr isKim\eSimulato r_original\src\ dist\library.zi p\matplotlib\__ init__.py:572: UserWarning: Could not find matplotlibrc; using defaults
    C:\Users\dmckin non\Desktop\Chr isKim\eSimulato r_original\src\ dist\library.zi p\matplotlib\__ init__.py:633: UserWarning: could not find rc file; returning defaults
    C:\Users\dmckin non\Desktop\Chr isKim\eSimulato r_original\src\ dist\library.zi p\matplotlib\__ init__.py:572: UserWarning: Could not find matplotlibrc; using defaults
    C:\Users\dmckin non\Desktop\Chr isKim\eSimulato r_original\src\ dist\library.zi p\matplotlib\__ init__.py:633: UserWarning: could not find rc file; returning defaults
    C:\Users\dmckin non\Desktop\Chr isKim\eSimulato r_original\src\ dist\library.zi p\matplotlib\__ init__.py:572: UserWarning: Could not find matplotlibrc; using defaults
    C:\Users\dmckin non\Desktop\Chr isKim\eSimulato r_original\src\ dist\library.zi p\matplotlib\__ init__.py:633: UserWarning: could not find rc file; returning defaults
    C:\Users\dmckin non\Desktop\Chr isKim\eSimulato r_original\src\ dist\library.zi p\matplotlib\__ init__.py:572: UserWarning: Could not find matplotlibrc; using defaults
    C:\Users\dmckin non\Desktop\Chr isKim\eSimulato r_original\src\ dist\library.zi p\matplotlib\__ init__.py:633: UserWarning: could not find rc file; returning defaults


    Basically, it is saying there is a "List Index out of range" in my code line 305

    What is the problem with my code line 305?
    I attached my program below...
    The line 305 looks like this
    Code:
    def refractorySimulation(self):
            delaysteps = [ 10, 12, 14, 16, 18, 20, 25, 30, 35]
            delay2 = delaysteps[self.counter]
            self.counter = self.counter + 1
            self.delay2_spinBox.setValue(delay2)
            self.updateSimulation()
            # This terminates the loop by setting the Qtimer to a single shot at the second last value of 'currentsteps'
            if (self.counter >= (len(delaysteps) - 1)):     
                self.timer.setSingleShot(True)
                localtimer = QtCore.QTimer()    # need this second timer to delay activation of widgets until after final run is finished
                localtimer.singleShot(800, self.activateControlWidgets)



    So please take a look at it and help me...

    Thank you very much in advance....
    Attached Files
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Apparently this line:
    Code:
    delay2 = delaysteps[self.counter]
    is the problem. self.counter must have been incremented to a number equal to the number of items in delaysteps.

    Code:
    >>> s = [1,2,3,4,5]
    >>> s[5]
    Traceback (most recent call last):
      File "<interactive input>", line 1, in ?
    IndexError: list index out of range
    >>>

    Comment

    • nakul27
      New Member
      • Aug 2010
      • 1

      #3
      That's correct, problem is with delaysteps, you need to do boundchecking for an array.

      IndexError: list index out of range, this error signifies that you are trying to access an element of an list which does not exist or say out or list range.

      Comment

      Working...