在python2.7中仍然有“__init __()关键字必须是字符串” - ReviewBoard

时间:2015-01-30 16:47:23

标签: python django review-board

我正在尝试安装ReviewBoard(https://www.reviewboard.org/),当我运行它时,我坚持使用“ init ()关键字必须是字符串”问题。

我读到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时,没有错误。

你有什么想法吗?

1 个答案:

答案 0 :(得分:2)

此错误产生如下(这是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中,我们可以手动指定关键字args,或者解压缩dict。让我们打开一个字典。

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

一切都是洁净的。但是,dicts更灵活,并且接受任何可清洗类型作为键,而不仅仅是字符串。如果我们这样做会怎么样?

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'),这当然没有意义。

希望这有帮助。