Python属性运行脚本时出错:type object'BaseCommand'没有属性'option_list' [英] Python Attribute Error when running script: type object 'BaseCommand' has no attribute 'option_list'

查看:886
本文介绍了Python属性运行脚本时出错:type object'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安装。

 追溯(最近的呼叫最后) :
文件manage.py,第10行在< module>
execute_from_command_line(sys.argv)
文件/usr/lib/python2.7/site-packages/Django-1.10.dev20151201151517-py2.7.egg/django/core/management/__init__.py ,第349行,在execute_from_command_line
utility.execute()
文件/usr/lib/python2.7/site-packages/Django-1.10.dev20151201151517-py2.7.egg/django/core /management/__init__.py,第341行,执行
self.fetch_command(子命令).run_from_argv(self.argv)
文件/usr/lib/python2.7/site-packages/Django -1.10.dev20151201151517-py2.7.egg / django / core / management / __ init__.py,第193行,fetch_command
klass = load_command_class(app_name,子命令)
文件/ usr / lib / python2.7 / site-packages / Django-1.10.dev20151201151517-py2.7.egg / django / core / management / __ init__.py,第40行,load_command_class
module = import_module('%s.management。命令%s'%(app_name,name))
文件/usr/lib64/python2.7/importlib/__init__.py,第37行,import_module
__import __(name)
文件/usr/lib/python2.7/site-packages/django_extensions-1.6.1-py2.7.egg/django_extensions/management/commands/runscript.py,第6行在< 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,第10行,< module>
class EmailNotificationCommand(BaseCommand):
文件/usr/lib/python2.7/site-packages/django_extensions-1.6.1-py2.7.egg/django_extensions/management/email_notifications.py,第49行,EmailNotificationCommand
** option_list = BaseCommand.option_list +(
AttributeError:类型对象'BaseCommand'没有属性'option_list'**
pre>

任何想法是什么问题是django中的一个错误?

解决方案

BaseCommand.option_list 在Django 1.8中被弃用,在Django 1.10中被删除,看起来像Django扩展已更新,但自那以后还没有发布新的版本。



您可以尝试从主分支安装django扩展,但使用最新版本的Django(目前为1.9.2)将是一个更好的主意。
Django 1.10尚未发布,目前仍在开发中。


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'**

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

解决方案

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.

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属性运行脚本时出错:type object'BaseCommand'没有属性'option_list'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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