Menu

IndexError at Tkinter.py (under Windows) - fix

Frank
2019-05-08
2020-08-19
  • Frank

    Frank - 2019-05-08

    In case it helps anyone:
    Running under Windows 10 64bit.
    User guide doesn't specify the required Python version. After some trial and error I got it working under Python 2.7 (not under 3.x).
    I got an IndexError at Tkinter.py when trying to run Demo #1:

      File "C:\Python27\lib\lib-tk\Tkinter.py", line 1820, in __init__
        baseName = os.path.basename(sys.argv[0])
    IndexError: list index out of range
    

    I fixed this by editing Tkinter.py, replacing the line

                baseName = os.path.basename(sys.argv[0])
    

    with the following:

                try:
                    sys.argv[0]
                except IndexError:
                    baseName = 'DSF_fitting.py'
                else:
                    baseName = os.path.basename(sys.argv[0])
    

    Then it worked.
    Obviously this doesn't look very tidy, as it introduces an ad-hoc exception check and a hard-coded string in a shared library. Is there a better way to fix this? (I don't have a lot of Python experience)

    Otherwise, very nice program, thanks!

     
  • John Karanicolas

    Hi Frank,

    Thank you for finding this problem, and especially for developing and sharing the solution! I hadn't tested this on a Windows machine, so I didn't know about this. Your solution will make it easier for others to use this program, so thank you for sharing!!

    John Karanicolas.

     
  • John Koberstein

    John Koberstein - 2019-11-06

    I also encountered this issue running on python 2.7 and Ubuntu 18.04. The root of the problem occurs at line 550 and 551:

    flags = sys.argv
    script_name = flags.pop(0)  # first item is the filename
    

    I think with flags being a shallow copy of sys.argv the pop operation ends up emptying sys.argv as well, which causes problems later when matplotlib tries to make use of sys.argv. This can be fixed by changing to :

    flags = deepcopy(sys.argv)
    
     
  • Raj Singh

    Raj Singh - 2020-08-17

    When I try to run this using Anaconda I get the following error.

    C:\WINDOWS\system32>C:\dsf_fitting\DSF_fitting.py
    File "C:\dsf_fitting\DSF_fitting.py", line 13
    print "\nHere are the supported flags:\n"
    ^
    SyntaxError: Missing parentheses in call to 'print'. Did you mean print("\nHere are the supported flags:\n")?

    In addition to installilng anaconda, I have Python, numpy, scipy, matplotlib installed on windows 10. everything is uptodate.
    -numpy, scipy, matplotlib were installed using Anaconda Prompt (Admin)
    Any help would be great.

     

    Last edit: Raj Singh 2020-08-17
  • John Karanicolas

    Hi Raj,
    I think this is a Python 2 versus Python 3 issue. Could you please check what version of Python you're running? Thanks,

    John.

     
  • Raj Singh

    Raj Singh - 2020-08-18

    Hi John,
    Thank you for responding. Yes I was able to get it to work with python 2.

    Thank you,
    Raj

     
  • John Karanicolas

    Hi Raj,
    Glad to hear it! Inspired by your comment I'm preparing a Python 3 version, and will update the code here very soon. Thanks for bringing this to my attention!

    John.

     
  • Raj Singh

    Raj Singh - 2020-08-18

    Hi John,
    Thanks for doing this. This goes without saying, on behalf of everyone using your script we really appreciate your work and thanks for making this available for everyone to use.

    Thank you,
    Rajdeep Virdi.

     

    Last edit: Raj Singh 2020-08-19
  • John Karanicolas

    Hi Raj,
    I've updated the code, the new version works with Python3. Thanks again for pointing this out!

    John.

     
  • Raj Singh

    Raj Singh - 2020-08-19

    Hi John,
    Just tested the updated version. Seems to work perfectly with Anaconda 3.

    Thank you,
    Raj

     

Log in to post a comment.