gpt4 book ai didi

python - python2.7 中仍然有 "__init__() keywords must be strings"- ReviewBoard

转载 作者:行者123 更新时间:2023-11-30 23:15:29 26 4
gpt4 key购买 nike

我正在尝试安装 ReviewBoard( https://www.reviewboard.org/ ),但在运行时遇到了“init() keywords必须是字符串”问题。

我读到这是python2.6中的常见问题。我检查过,我有python2.6,所以我安装了python2.7,但问题仍然存在。

[Fri Jan 30 16:02:11 2015] [error] mod_wsgi (pid=12875): Exception occurred processing WSGI script '/srv/www/htdocs/tools/reviewboard/htdocs/reviewboard.py'.
[Fri Jan 30 16:02:11 2015] [error] Traceback (most recent call last):
[Fri Jan 30 16:02:11 2015] [error] File "/usr/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/core/handlers/wsgi.py", line 187, in __call__
[Fri Jan 30 16:02:11 2015] [error] self.load_middleware()
[Fri Jan 30 16:02:11 2015] [error] File "/usr/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/core/handlers/base.py", line 45, in load_middleware
[Fri Jan 30 16:02:11 2015] [error] mw_class = import_by_path(middleware_path)
[Fri Jan 30 16:02:11 2015] [error] File "/usr/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/utils/module_loading.py", line 21, in import_by_path
[Fri Jan 30 16:02:11 2015] [error] module = import_module(module_path)
[Fri Jan 30 16:02:11 2015] [error] File "/usr/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/utils/importlib.py", line 40, in import_module
[Fri Jan 30 16:02:11 2015] [error] __import__(name)
[Fri Jan 30 16:02:11 2015] [error] File "/usr/local/lib/python2.7/site-packages/ReviewBoard-2.0.12-py2.7.egg/reviewboard/admin/middleware.py", line 23, in <module>
[Fri Jan 30 16:02:11 2015] [error] from reviewboard.admin.checks import check_updates_required
[Fri Jan 30 16:02:11 2015] [error] File "/usr/local/lib/python2.7/site-packages/ReviewBoard-2.0.12-py2.7.egg/reviewboard/admin/checks.py", line 41, in <module>
[Fri Jan 30 16:02:11 2015] [error] from djblets.siteconfig.models import SiteConfiguration
[Fri Jan 30 16:02:11 2015] [error] File "/usr/local/lib/python2.7/site-packages/Djblets-0.8.14-py2.7.egg/djblets/siteconfig/models.py", line 28, in <module>
[Fri Jan 30 16:02:11 2015] [error] from django.contrib.sites.models import Site
[Fri Jan 30 16:02:11 2015] [error] File "/usr/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/contrib/sites/models.py", line 58, in <module>
[Fri Jan 30 16:02:11 2015] [error] class Site(models.Model):
[Fri Jan 30 16:02:11 2015] [error] File "/usr/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/db/models/base.py", line 96, in __new__
[Fri Jan 30 16:02:11 2015] [error] new_class.add_to_class('_meta', Options(meta, **kwargs))
[Fri Jan 30 16:02:11 2015] [error] TypeError: Error when calling the metaclass bases
[Fri Jan 30 16:02:11 2015] [error] __init__() keywords must be strings

我应该提到的是python2.6仍然安装,所以也许这就是问题所在?在apache配置文件中,我指向python2.7,如果删除该行,它正在使用python2.6。

WSGIDaemonProcess example.com python-path=/srv/www/htdocs/tools/reviewboard/htdocs:/usr/local/lib/python2.7/site-packages

我也尝试使用:

WSGIPythonHome /usr/local/lib/python2.7
WSGIPythonPath /usr/local/lib/python2.7

但是它给了我:

[Fri Jan 30 17:01:38 2015] [error]  mod_wsgi (pid=11500): Target WSGI script '/srv/www/htdocs/tools/reviewboard/htdocs/reviewboard.py' cannot be loaded as Python module.
[Fri Jan 30 17:01:38 2015] [error] mod_wsgi (pid=11500): Exception occurred processing WSGI script '/srv/www/htdocs/tools/reviewboard/htdocs/reviewboard.py'.
[Fri Jan 30 17:01:38 2015] [error] Traceback (most recent call last):
[Fri Jan 30 17:01:38 2015] [error] File "/srv/www/htdocs/tools/reviewboard/htdocs/reviewboard.py", line 3, in <module>
[Fri Jan 30 17:01:38 2015] [error] import pkg_resources
[Fri Jan 30 17:01:38 2015] [error] ImportError: No module named pkg_resources

重新安装设置工具( https://pypi.python.org/pypi/setuptools ) 没有帮助

当我从控制台运行 python2.7 或 python2.6 并导入 pkg_resources 时,没有错误。

您知道这里出了什么问题吗?

最佳答案

这个错误的产生如下(这是Python 2.7.9,但并不重要)。

def function(*args, **kwargs):
print u'I got args: %s' % u', '.join(args)
print u'I got kwrgs: %s' % u', '.join(u'%s=%s' % (k, v)
for k, v in kwargs.items())

这个函数将打印出我们传递给它的任何内容。在Python中,我们可以手动指定关键字参数,或者解压一个字典。让我们解压一个字典。

kwargs = {'a': 1, 'b': 2}
function(**kwargs)
I got args:
I got kwargs: a=1, b=2

一切都是洁净的。然而,字典更灵活,接受任何可哈希类型作为键,而不仅仅是字符串。如果我们这样做会发生什么?

kwargs[(0, 1)] = 'five'    # tuples are hashable and can be dict keys

现在,如果我们调用函数:

function(**kwargs)

我们得到:

TypeError: function() keywords must be strings

因为它试图解压成 function(a=1, b=2, (0, 1)=' Five'),这当然没有意义。

希望这有帮助。

关于python - python2.7 中仍然有 "__init__() keywords must be strings"- ReviewBoard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28240664/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com