Python/Django shell无法启动

dan*_*mer 7 python django shell

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

$ python manage.py shell
Run Code Online (Sandbox Code Playgroud)

我刚开始开发一个新项目,由于某种原因,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'
Run Code Online (Sandbox Code Playgroud)

在此先感谢您的帮助!

Dan*_*man 12

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

./manage.py shell --plain
Run Code Online (Sandbox Code Playgroud)

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


vdb*_*oor 6

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

对于较旧的Django版本,您可以使用IPython 0.10,它可以工作:

pip install ipython==0.10
Run Code Online (Sandbox Code Playgroud)

  • @brianray:这是可能的,我可以确认`rm -Rf~/.ipython /`是一个很好的解决方法. (2认同)