Python 库中的语法错误,我不知道如何继续 [英] Syntax error in a Python library, and I'm not sure how to proceed

查看:55
本文介绍了Python 库中的语法错误,我不知道如何继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是金字塔 1.5.1 和 python 3.2,我只是在我的项目中添加了相当多的代码和几个库.

在运行 development.ini 时,我收到以下错误.

如果我不得不胡乱猜测,我会说这个特定的库(看起来像 Markupsafe?)与 Python3 不兼容……但项目页面似乎表明它是.问题是,我没有直接调用这个库,它正被另一个很难替换的库使用.

我是 Python 编程的新手,我想知道这里有哪些选择,或者最好的调试方法是什么?

(finance-env)user1@finance1:/var/www/finance/corefinance/corefinance$/var/www/finance/finance-env/bin/pserve/var/www/finance/corefinance/development.ini --reload使用文件监视器启动子进程回溯(最近一次调用最后一次):文件/var/www/finance/finance-env/bin/pserve",第 9 行,在 <module> 中.load_entry_point('金字塔==1.5.1',​​ 'console_scripts', 'pserve')()文件/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/scripts/pserve.py",第51行,主返回 command.run()运行中的文件/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/scripts/pserve.py",第 316 行global_conf=vars)文件/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/scripts/pserve.py",第340行,在loadapp中返回 loadapp(app_spec, name=name, relative_to=relative_to, **kw)文件/var/www/finance/finance-env/lib/python3.2/site-packages/paste/deploy/loadwsgi.py",第 247 行,在 loadapp 中返回 loadobj(APP, uri, name=name, **kw)文件/var/www/finance/finance-env/lib/python3.2/site-packages/paste/deploy/loadwsgi.py",第272行,在loadobj中返回 context.create()文件/var/www/finance/finance-env/lib/python3.2/site-packages/paste/deploy/loadwsgi.py",第710行,在创建返回 self.object_type.invoke(self)文件/var/www/finance/finance-env/lib/python3.2/site-packages/paste/deploy/loadwsgi.py",第 146 行,在调用中返回 fix_call(context.object, context.global_conf, **context.local_conf)文件/var/www/finance/finance-env/lib/python3.2/site-packages/paste/deploy/util.py",第 55 行,在 fix_callval = callable(*args, **kw)文件/var/www/finance/corefinance/corefinance/__init__.py", line 35, in mainsession_factory=session_factory文件/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/config/__init__.py",第301行,在__init__异常响应_视图=异常响应_视图,setup_registry 中的文件/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/config/__init__.py",第 412 行self.include(inc)文件/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/config/__init__.py",第755行,包含c(配置器)文件/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid_debugtoolbar-2.1-py3.2.egg/pyramid_debugtoolbar/__init__.py",第113行,包含我config.include('pyramid_mako')文件/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/config/__init__.py",第727行,包含c = self.maybe_dotted(可调用)文件/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/config/__init__.py",第825行,在maybe_dotted返回 self.name_resolver.maybe_resolve(虚线)文件/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/path.py",第320行,在maybe_resolve返回 self._resolve(dotted, package)文件/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/path.py",第 327 行,在 _resolve返回 self._zope_dottedname_style(dotted, package)文件/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid/path.py",第370行,_zope_dottedname_style找到 = __import__(使用)文件/var/www/finance/finance-env/lib/python3.2/site-packages/pyramid_mako-1.0.2-py3.2.egg/pyramid_mako/__init__.py",第18行,在<module>从 mako.lookup 导入 TemplateLookup文件/var/www/finance/finance-env/lib/python3.2/site-packages/Mako-1.0.0-py3.2.egg/mako/lookup.py",第9行,在<module>from mako.template 导入模板文件/var/www/finance/finance-env/lib/python3.2/site-packages/Mako-1.0.0-py3.2.egg/mako/template.py",第10行,在<module>从 mako.lexer 导入 Lexer文件/var/www/finance/finance-env/lib/python3.2/site-packages/Mako-1.0.0-py3.2.egg/mako/lexer.py",第11行,在<module>从 mako 导入解析树,异常,兼容文件/var/www/finance/finance-env/lib/python3.2/site-packages/Mako-1.0.0-py3.2.egg/mako/parsetree.py",第9行,在<module>从 mako 导入异常、ast、util、过滤器、compat文件/var/www/finance/finance-env/lib/python3.2/site-packages/Mako-1.0.0-py3.2.egg/mako/filters.py",第38行,在<module>导入标记安全文件/var/www/finance/finance-env/lib/python3.2/site-packages/MarkupSafe-0.23-py3.2-linux-x86_64.egg/markupsafe/__init__.py",第70行def __new__(cls, base=u'', encoding=None, errors='strict'):^语法错误:无效语法

解决方案

MarkupSafe 包使用仅 Python 3.3 及更高版本支持的语法.从 0.16 版起,不再支持 Python 3.2.>

u'unicode' 文字语法是在 PEP 414 以便更轻松地创建可以支持 Python 2 和 3 的库代码.

要么升级到 Python 3.3(甚至 3.4),要么将 MarkupSafe 降级到 0.15,这是支持 Python 3.2 的最后一个版本.

我确实看到 Mako 删除MarkupSafe代码>依赖,当你使用Python 3.2时;如果没有其他依赖,完全删除包裹也许是安全的.mako.filter源代码肯定会回退到本地实现.

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

解决方案

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.

The u'unicode' literal syntax was introduced in PEP 414 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 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 certainly will fall back to a local implementation if the package is not installed.

这篇关于Python 库中的语法错误,我不知道如何继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆