Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.


nonlocal doesn't worl with 2.X

  • andrewsben

    line 629 of pyparser sets nonlocal variables limit and foundArity.  In python 2.X nonlocal variables are read only and cannot be set.  In the following lines setting them is attempted. 

    'decorator to trim function calls to match the arity of the target'
    def _trim_arity(func, maxargs=3):
        if func in singleArgBuiltins:
            return lambda s,l,t: func(t)
        limit = 0
        foundArity = False
        def wrapper(*args):
            nonlocal limit,foundArity
            while 1:
                    ret = func(*args)
                    foundArity = True
                    return ret
                except TypeError:
                    if limit == maxargs or foundArity:
                    limit += 1
        return wrapper

    Error i am seeing is:

      File "/tmp/easy_install-7t56MV/pyparsing-2.0.0/", line 629
        nonlocal limit,foundArity
    SyntaxError: invalid syntax

  • Paul McGuire
    Paul McGuire

    Pyparsing 2.0.0 is for Python 3 only - latest pyparsing version for Python 2.x is 1.5.7.

  • Paul McGuire
    Paul McGuire

    To do this with easy_install, use the command "easy_install pyparsing==1.5.7"

  • andrewsben

    Thanks for the information.  Will alter my script to force 1.5.7.

  • It's of course fine to have newer versions only support Python 3 but the way this change is introduced is probably breaking a lot of automatic testing code (like mine) that just uses the newest pyparsing version available. In addition, installation via "easy_install pyparsing" and "pip install pyparsing" is impossible on Python 2 and does not give any useful error message.

    I'm not sure:  Does pip take the package meta-data into account? If yes, removing "Programming Language :: Python" and only keeping "Programming Language :: Python :: 3" might prevent pip from trying to install it under python 2.

    Either way, I think it would be a good idea to add a check to, something along the lines of:

    if sys.hexversion <= 0x03000000:
      raise Exception('This version of pyparsing requires Python 3, 1.5.7 is the last version supporting Python 2.')

    Oh, and the README file still states:
    "(pyparsing requires Python 2.3.2 or later.)"

  • francoise

    I am unable to install the 1.5.7 release with pip :

    $ pip install pyparsing==1.5.7

    It's like the 1.5.7 release was overwritten by the new version ?

  • Jimmy Royer
    Jimmy Royer

    Same problem over here, I cannot install with

    pip install pyparsing==1.5.7

    and the documentation for version 2.0.0 still list 2.3.2 as compatible. I had to come here to find out. Any place where we can download a previous version?


  • Anonymous

    If you tried to install the lastest version before, you need to clear the pip cache  before trying to install a previous version

  • I see

    And solved this with

    $ pip install
  • Dan Gayle
    Dan Gayle

    pip install pyparsing==1.5.6    
    pip install pyparsing==1.5.7

    ^ Doesn't work on Python 2.7.5

    easy_install pyparsing==1.5.7

    ^ Works

    What's more concerning is that pyparsing is part of Celery's requirements, and it borks on this error trying to install.

    Last edit: Dan Gayle 2013-07-08
    • Paul McGuire
      Paul McGuire

      Thanks for the reminder - I'm checking in version 2.0.1 of pyparsing, which
      will be compatible with Pythons 2.6 and 2.7 also.

      -- Paul

      From: Dan Gayle []
      Sent: Monday, July 08, 2013 6:45 PM
      To: [pyparsing:discussion]
      Subject: [pyparsing:discussion] nonlocal doesn't worl with 2.X

      pip install pyparsing==1.5.7

      ^ Doesn't work on Python 2.7.5

      pip install pyparsing==1.5.6

      ^ Works

      What's more concerning is that pyparsing is part of Celery's requirements,
      and it borks on this error trying to install.

      nonlocal doesn't worl with 2.X t=25#2ce7

      Sent from because you indicated interest in

      To unsubscribe from further messages, please visit