Python/Django shell 无法启动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2078059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 23:42:42  来源:igfitidea点击:

Python/Django shell won't start

pythondjangoshell

提问by danpalmer

One of the great features of Django is that you can open a python interpreter set-up for use with your project. This can be used to analyse objects in a database and allows any python commands to be executed on your project. I find it essential for Django development. It is invoked in the project directory using this command:

Django 的一大特色是您可以打开 Python 解释器设置以用于您的项目。这可用于分析数据库中的对象,并允许在您的项目上执行任何 python 命令。我发现它对 Django 开发至关重要。使用以下命令在项目目录中调用它:

$ python manage.py shell

I have just started developing a new project and for some reason the shell does not work. I have had a look online for the error and not found anything. I would greatly appreciate any help on this error:

我刚刚开始开发一个新项目,由于某种原因,shell 不起作用。我在网上查看了错误,但没有发现任何问题。我将不胜感激对此错误的任何帮助:


Traceback (most recent call last):
  File "manage.py", line 11, in 
    execute_manager(settings)
  File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 362, in execute_manager
    utility.execute()
  File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 303, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 195, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 222, in execute
    output = self.handle(*args, **options)
  File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "/Library/Python/2.6/site-packages/django/core/management/commands/shell.py", line 29, in handle_noargs
    shell = IPython.Shell.IPShell(argv=[])
AttributeError: 'module' object has no attribute 'Shell'

Thanks in advance for your help!

在此先感谢您的帮助!

回答by Daniel Roseman

It seems like IPython is installed wrongly somehow. Try starting the shell with:

似乎 IPython 以某种方式安装错误。尝试使用以下命令启动 shell:

./manage.py shell --plain

to start the standard Python shell, rather than IPython. If that works, then trying removing IPython completely and reinstalling it.

启动标准 Python shell,而不是 IPython。如果可行,则尝试完全删除 IPython 并重新安装它。

回答by vdboor

IPython 0.11 has a different API, for which a fix exists in the last Django versions.

IPython 0.11 有一个不同的 API,在最新的 Django 版本中存在修复。

For older Django versions, you can use IPython 0.10, which does work:

对于较旧的 Django 版本,您可以使用 IPython 0.10,它确实有效:

pip install ipython==0.10