gpt4 book ai didi

python - django-scarface 无法在 python 2.7 中工作

转载 作者:行者123 更新时间:2023-12-01 04:03:29 25 4
gpt4 key购买 nike

我的操作系统是 OSX El Capitan。

版本:

  • Python 2.7.10
  • Django 1.9.2
  • Django -疤面煞星 3.0

在我安装疤面并将其添加到已安装的应用程序中后,它出现此错误,并且我无法运行我的应用程序。

Unhandled exception in thread started by <function wrapper at 0x1043dbe60>
Traceback (most recent call last):
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/scarface/models.py", line 7, in <module>
from scarface.platform_strategy import get_strategies
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/scarface/platform_strategy.py", line 38
class PlatformStrategy(metaclass=ABCMeta):
^
SyntaxError: invalid syntax

在我搜索这个错误之后,我认为原因是我的python版本。我还是不确定,所以才来问你。

有什么办法可以解决这个问题吗?如果原因确实是我的 Python 版本,我怎样才能更新我的 Python 版本而不损坏我的代码和所有内容?

最佳答案

该问题与 Python 3.x ( https://docs.python.org/3/whatsnew/3.0.html?highlight=metaclass#changed-syntax ) 中的元类语法更改有关,django-scarface 是面向 3.x 的。我解决了这个问题(使用Python 2.7.x),将platform_strategy.py(第38行)更改为:

class PlatformStrategy():
__metaclass__ = ABCMeta

我在github项目中提交了一个pull request:https://github.com/dreipol/django-scarface/pull/11

关于python - django-scarface 无法在 python 2.7 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36100771/

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