Syntax error in a Python library, and I'm not sure how to proceed
Question: I'm using pyramid 1.5.1 and python 3.2, and I just added quite a bit of code
and a couple libraries to my project.

On running development.ini, I'm getting the error below.

If I had to take a wild guess, I would say that this particular library (looks
like Markupsafe?) isn't compatible with Python3...but the project page seems
to indicate that it is. Problem is, I'm not calling this library directly,
it's being used by another library that would be very difficult to replace.

I'm new to Python programming, and I was wondering what my options are here Or
what the best way to debug is?

    
    
    (finance-env)user1@finance1:/var/www/finance/corefinance/corefinance$ /var/www/finance/finance-env/bin/pserve /var/www/finance/corefinance/development.ini --reload
    Starting subprocess with file monitor
    Traceback (most recent call last):
      File "/var/www/finance/finance-env/bin/pserve", line 9, in <module>
        load_entry_point('pyramid==1.5.1', 'console_scripts', 'pserve')()
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/scripts/pserve.py", line 51, in main
        return command.run()
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/scripts/pserve.py", line 316, in run
        global_conf=vars)
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/scripts/pserve.py", line 340, in loadapp
        return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
        return loadobj(APP, uri, name=name, **kw)
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/paste/deploy/loadwsgi.py", line 272, in loadobj
        return context.create()
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/paste/deploy/loadwsgi.py", line 710, in create
        return self.object_type.invoke(self)
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/paste/deploy/loadwsgi.py", line 146, in invoke
        return fix_call(context.object, context.global_conf, **context.local_conf)
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/paste/deploy/util.py", line 55, in fix_call
        val = callable(*args, **kw)
      File "/var/www/finance/corefinance/corefinance/__init__.py", line 35, in main
        session_factory=session_factory
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/config/__init__.py", line 301, in __init__
        exceptionresponse_view=exceptionresponse_view,
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/config/__init__.py", line 412, in setup_registry
        self.include(inc)
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/config/__init__.py", line 755, in include
        c(configurator)
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid_debugtoolbar-2.1-py3.2.egg/pyramid_debugtoolbar/__init__.py", line 113, in includeme
        config.include('pyramid_mako')
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/config/__init__.py", line 727, in include
        c = self.maybe_dotted(callable)
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/config/__init__.py", line 825, in maybe_dotted
        return self.name_resolver.maybe_resolve(dotted)
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/path.py", line 320, in maybe_resolve
        return self._resolve(dotted, package)
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/path.py", line 327, in _resolve
        return self._zope_dottedname_style(dotted, package)
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/path.py", line 370, in _zope_dottedname_style
        found = __import__(used)
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid_mako-1.0.2-py3.2.egg/pyramid_mako/__init__.py", line 18, in <module>
        from mako.lookup import TemplateLookup
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/Mako-1.0.0-py3.2.egg/mako/lookup.py", line 9, in <module>
        from mako.template import Template
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/Mako-1.0.0-py3.2.egg/mako/template.py", line 10, in <module>
        from mako.lexer import Lexer
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/Mako-1.0.0-py3.2.egg/mako/lexer.py", line 11, in <module>
        from mako import parsetree, exceptions, compat
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/Mako-1.0.0-py3.2.egg/mako/parsetree.py", line 9, in <module>
        from mako import exceptions, ast, util, filters, compat
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/Mako-1.0.0-py3.2.egg/mako/filters.py", line 38, in <module>
        import markupsafe
      File "/var/www/finance/finance-env/lib/python3.2/site-packages/MarkupSafe-0.23-py3.2-linux-x86_64.egg/markupsafe/__init__.py", line 70
        def __new__(cls, base=u'', encoding=None, errors='strict'):
                                ^
    SyntaxError: invalid syntax
    


Answer: The `MarkupSafe` package uses syntax only supported by Python 3.3 and up.
Python 3.2 is not supported anymore as of [version
0.16](https://github.com/mitsuhiko/markupsafe/blob/master/CHANGES#L14-L18).

The `u'unicode'` literal syntax was introduced in [PEP
414](https://docs.python.org/3/whatsnew/3.3.html#pep-414-explicit-unicode-
literals) to make it easier to create library code that can support both
Python 2 and 3.

Either upgrade to Python 3.3 (or 3.4 even), or downgrade `MarkupSafe` to 0.15,
the last version to support Python 3.2.

I do see that [Mako _removes_ the `MarkupSafe`
dependency](https://bitbucket.org/zzzeek/mako/commits/4acc7ecaafdc1c36602d3ed7c02892c04210de13)
when you are using Python 3.2; if nothing else depends on it is perhaps safe
to remove the package altogether. The [`mako.filter` source
code](https://bitbucket.org/zzzeek/mako/src/285bc818a50ccc0f9549630f7c4f4c250585c3e7/mako/filters.py?at=master#cl-37)
certainly will fall back to a local implementation if the package is not
installed.

