InteractiveShellEmbed的多个不兼容的子类实例

InteractiveShellEmbed的多个不兼容的子类实例

本文介绍了正在创建InteractiveShellEmbed的多个不兼容的子类实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我安装了,并尝试运行 ipython manage.py shell 从我的django应用程序,下面的错误被抛出。我知道,当我安装anaconda,它包装与python和ipython的版本不同于其他python / ipython版本。但是不管ipython版本如何,为什么django shell会抛出错误?我尝试卸载系统ipython,同样的错误被抛出,这意味着anaconda ipython分发和django有一些问题。卸载anaconda可以解决问题。

If I install the Anaconda Python Distribution and try to run ipython manage.py shell from within my django app, the error below is thrown. I know that when I install anaconda, it comes packaged with python and ipython whose version differs from the other python/ipython versions I have. But irrespective of the ipython version, why should the django shell throw an error? I tried uninstalling the system ipython and the same error gets thrown, which implies that there is some issue with the anaconda ipython distribution and django. Uninstalling anaconda solves the problem.

堆栈跟踪

manage.py in <module>()
      9
     10 if __name__ == "__main__":
---> 11     execute_manager(settings)

lib/python2.7/site-packages/django/core/management/__init__.pyc in execute_manager(settings_mod, argv)
    457     setup_environ(settings_mod)
    458     utility = ManagementUtility(argv)
--> 459     utility.execute()

lib/python2.7/site-packages/django/core/management/__init__.pyc in execute(self)
    380             sys.stdout.write(self.main_help_text() + '\n')
    381         else:
--> 382             self.fetch_command(subcommand).run_from_argv(self.argv)
    383
    384 def setup_environ(settings_mod, original_settings_path=None):

lib/python2.7/site-packages/django/core/management/base.pyc in run_from_argv(self, argv)
    194         options, args = parser.parse_args(argv[2:])
    195         handle_default_options(options)
--> 196         self.execute(*args, **options.__dict__)
    197
    198     def execute(self, *args, **options):

lib/python2.7/site-packages/django/core/management/base.pyc in execute(self, *args, **options)
    230             if self.requires_model_validation:
    231                 self.validate()
--> 232             output = self.handle(*args, **options)
    233             if output:
    234                 if self.output_transaction:

lib/python2.7/site-packages/django/core/management/base.pyc in handle(self, *args, **options)
    369         if args:
    370             raise CommandError("Command doesn't accept any arguments")
--> 371         return self.handle_noargs(**options)
    372
    373     def handle_noargs(self, **options):

lib/python2.7/site-packages/django_extensions/management/commands/shell_plus.pyc in handle_noargs(self, **options)
    116                 try:
    117                     from IPython import embed
--> 118                     embed(user_ns=imported_objects)
    119                 except ImportError:
    120                     # IPython < 0.11

lib/python2.7/site-packages/IPython/terminal/embed.pyc in embed(**kwargs)
    298         config.InteractiveShellEmbed = config.TerminalInteractiveShell
    299         kwargs['config'] = config
--> 300     shell = InteractiveShellEmbed.instance(**kwargs)
    301     shell(header=header, stack_depth=2, compile_flags=compile_flags)

lib/python2.7/site-packages/IPython/config/configurable.pyc in instance(cls, *args, **kwargs)
    358             raise MultipleInstanceError(
    359                 'Multiple incompatible subclass instances of '
--> 360                 '%s are being created.' % cls.__name__
    361             )
    362

MultipleInstanceError: Multiple incompatible subclass instances of InteractiveShellEmbed are being created.


推荐答案

您要使用

python manage.py shell

不是

ipython manage.py shell

manage.py shell启动一个嵌入式IPython实例。当您通过 ipython manage.py 运行它时,您将启动一个常规IPython会话,您可以在其中运行尝试嵌入IPython的脚本。这意味着您将启动两个IPython实例。这是因为IPython无法嵌入到本身中。

manage.py shell starts an embedded IPython instance. When you run this via ipython manage.py, you are starting a regular IPython session, in which you run a script that tries to embed IPython. That means you are starting two instances of IPython. This fails because IPython cannot be embedded in itself.

这篇关于正在创建InteractiveShellEmbed的多个不兼容的子类实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 23:49