运行脚本时出现 Python 属性错误:类型对象“BaseCommand"没有属性“option_list" [英] Python Attribute Error when running script: type object 'BaseCommand' has no attribute 'option_list'

查看:36
本文介绍了运行脚本时出现 Python 属性错误:类型对象“BaseCommand"没有属性“option_list"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了这篇关于如何从 django 运行 python 脚本的帖子:http://www.djangotutsme.com/how-to-run-python-script-from-django/
我尝试了该示例,但在运行 python manage.py runscript myscript 时出现以下错误.我安装了 Python 2.7、Django 1.10 和 django 扩展 1.6.1.

I saw this post on how to run a python script from django: http://www.djangotutsme.com/how-to-run-python-script-from-django/
I tried the example but get the following error when running python manage.py runscript myscript. I have Python 2.7, Django 1.10 and django extensions 1.6.1 installed.

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.7/site-packages/Django-1.10.dev20151201151517-py2.7.egg/django/core/management/__init__.py", line 349, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.7/site-packages/Django-1.10.dev20151201151517-py2.7.egg/django/core/management/__init__.py", line 341, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.7/site-packages/Django-1.10.dev20151201151517-py2.7.egg/django/core/management/__init__.py", line 193, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/usr/lib/python2.7/site-packages/Django-1.10.dev20151201151517-py2.7.egg/django/core/management/__init__.py", line 40, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/lib/python2.7/site-packages/django_extensions-1.6.1-py2.7.egg/django_extensions/management/commands/runscript.py", line 6, in <module>
    from django_extensions.management.email_notifications import 
  File "/usr/lib/python2.7/site-packages/django_extensions-1.6.1-py2.7.egg/django_extensions/management/email_notifications.py", line 10, in <module>
    class EmailNotificationCommand(BaseCommand):
  File "/usr/lib/python2.7/site-packages/django_extensions-1.6.1-py2.7.egg/django_extensions/management/email_notifications.py", line 49, in EmailNotificationCommand
    **option_list = BaseCommand.option_list + (
AttributeError: type object 'BaseCommand' has no attribute 'option_list'**

知道是什么问题吗?这是 Django 中的错误吗?

Any idea what the problem is? Is this a bug in django?

推荐答案

BaseCommand.option_list 在 Django 1.8 中被弃用,在 Django 1.10 中被移除.看起来 Django-extensions 已经更新,但是没有更新从那以后一直是一个新版本.

BaseCommand.option_list is deprecated in Django 1.8 and removed in Django 1.10. It looks like Django-extensions has been updated, but there hasn't been a new release since then.

您可以尝试从 master 分支安装 django-extensions,但最好使用最新版本的 Django,目前是 1.9.2.Django 1.10 尚未发布,仍在开发中.

You could try installing django-extensions from the master branch, but it would be a better idea to use the latest release of Django, currently 1.9.2. Django 1.10 has not been released yet, and is still under development.

这篇关于运行脚本时出现 Python 属性错误:类型对象“BaseCommand"没有属性“option_list"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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