简体   繁体   English

Python / Django shell无法启动

[英]Python/Django shell won't start

One of the great features of Django is that you can open a python interpreter set-up for use with your project. Django的一个重要特性是你可以打开一个python解释器设置,用于你的项目。 This can be used to analyse objects in a database and allows any python commands to be executed on your project. 这可用于分析数据库中的对象,并允许在项目上执行任何python命令。 I find it essential for Django development. 我发现Django开发很重要。 It is invoked in the project directory using this command: 使用以下命令在项目目录中调用它:

$ python manage.py shell

I have just started developing a new project and for some reason the shell does not work. 我刚开始开发一个新项目,由于某种原因,shell不起作用。 I have had a look online for the error and not found anything. 我已经在线查看错误,但没有找到任何内容。 I would greatly appreciate any help on this error: 我非常感谢有关此错误的任何帮助:


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! 在此先感谢您的帮助!

It seems like IPython is installed wrongly somehow. 似乎IPython以某种方式错误地安装。 Try starting the shell with: 尝试使用以下命令启动shell:

./manage.py shell --plain

to start the standard Python shell, rather than IPython. 启动标准的Python shell,而不是IPython。 If that works, then trying removing IPython completely and reinstalling it. 如果可行,那么尝试完全删除IPython并重新安装它。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM