Difficulty with "inconsistent use of tabs and spaces in indentation"in file called <string>

Discussion in 'Python' started by ibloom, Feb 11, 2008.

  1. ibloom

    ibloom Guest

    I've been trying for a couple days to build a program using pyObjC on
    a mac, I'm stuck on this error:

    <string>: inconsistent use of tabs and spaces in indentation
    Traceback (most recent call last):
    File "setup.py", line 59, in ?
    setup(**setup_options)
    File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
    python2.4/distutils/core.py", line 149, in setup
    dist.run_commands()
    File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
    python2.4/distutils/dist.py", line 946, in run_commands
    self.run_command(cmd)
    File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
    python2.4/distutils/dist.py", line 966, in run_command
    cmd_obj.run()
    File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
    python2.4/site-packages/py2app/py2app/build_app.py", line 342, in run
    self.initialize_plist()
    File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
    python2.4/site-packages/py2app/py2app/build_app.py", line 415, in
    initialize_plist
    plist = self.get_default_plist()
    File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
    python2.4/site-packages/py2app/py2app/build_app.py", line 294, in
    get_default_plist
    version = find_version(target.script)
    File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
    python2.4/site-packages/py2app/py2app/util.py", line 13, in
    find_version
    ast = compiler.parseFile(fn)
    File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
    python2.4/compiler/transformer.py", line 48, in parseFile
    return parse(src)
    File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
    python2.4/compiler/transformer.py", line 52, in parse
    return Transformer().parsesuite(buf)
    File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
    python2.4/compiler/transformer.py", line 129, in parsesuite
    return self.transform(parser.suite(text))
    File "<string>", line 628
    else:
    ^
    SyntaxError: invalid syntax

    I don't even know which file has the indentation problem.

    Any thoughts.
    Ian Bloom
     
    ibloom, Feb 11, 2008
    #1
    1. Advertisements

  2. Put a print statement just above that line, to see which file triggers the
    error.
     
    Gabriel Genellina, Feb 11, 2008
    #2
    1. Advertisements

  3. ibloom

    mensanator Guest

    Maybe none of them do. An indentation error isn't necessarily
    due to indentation. I just saw one last Saturday, but I don't
    remember what caused it other than it wasn't indentation.
    Something was open that wasn't closed properly, such as
    matching () or [] or ''. Unfortunately, I can't reproduce it.
    Examine the code carefully in the sections before the actual
    reported error. You may be seeing a symptom rather than the cause.
     
    mensanator, Feb 11, 2008
    #3
  4. ibloom

    ibloom Guest

    My main problem is, I don't know where to find the file:
    File "<string>", line 628

    As in I don't know what code it is refering to by <string> ??
    It isn't code that I wrote, its something from python or pyObjC

    Ian Bloom
     
    ibloom, Feb 11, 2008
    #4
  5. ibloom

    Steve Holden Guest

    You'll typically see that in code that's being executed from a
    dynamically created string in the code, which is going to make it *very*
    difficult to debug.
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>

    regards
    Steve
     
    Steve Holden, Feb 12, 2008
    #5
  6. Mmm, didn't you get my previous post? The call is inside the py2app
    package. Quoting myself:
    In case it wasn't clear, modify the file
    /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/py2app/py2app/util.py,
    around line 13, in the find_version function, adding this print statement:

    print 'about to compile', fn
    ast = compiler.parseFile(fn)

    The last line printed (in case there are many) should be the offending
    filename.

    Of course you don't have to keep the modified library, this is just to
    detect which file triggers the error. You should report this to the py2app
    developers as well.
     
    Gabriel Genellina, Feb 12, 2008
    #6
  7. ibloom

    ibloom Guest

    You are right, I didn't understand. I'll try it. Thank you.

    Ian Bloom
     
    ibloom, Feb 12, 2008
    #7
  8. ibloom

    ibloom Guest

    Gabriel, your the master.
    Of course I didn't understand that py2app was trying to compile my own
    python source code and when I switched to Xcode as my new editor, I
    started mixing in tabs. So <string> was in fact my code. All I had to
    do was change my preferences in Xcode, to generate spaces instead of
    tabs, remove all of the offending tabs and voila. You've ended days of
    frustrations. Thank you.

    Ian Bloom
     
    ibloom, Feb 13, 2008
    #8
  9. ibloom

    greg Guest

    Seems like py2app could be a bit friendlier about reporting
    syntax errors in the code it's trying to compile!
     
    greg, Feb 13, 2008
    #9
  10. Glad to be of any help. Note that all the clues were on the traceback.
    When people here insist that all error reports should come with the
    complete stack trace, it isn't because they want to be annoying, but
    because it's really useful...
     
    Gabriel Genellina, Feb 13, 2008
    #10
  11. Glad to be of any help. Note that all the clues were on the traceback.
    When people here insist that all error reports should come with the
    complete stack trace, it isn't because they want to be annoying, but
    because it's really useful...
     
    Gabriel Genellina, Feb 13, 2008
    #11
  12. Yes, but the standard "compiler" package (used by py2app) is somewhat
    guilty too. The parseFile function is called with a file name, but such
    info is lost and the filename isn't used in the error messages. Compare
    with the builtin "compile" function, which *does* use the supplied file
    name to report meaningful errors.
     
    Gabriel Genellina, Feb 13, 2008
    #12
  13. Gabriel Genellina a écrit :
    (snip)
    +1 QOTW
     
    Bruno Desthuilliers, Feb 13, 2008
    #13
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.