Python/Django shell无法启动
Django的一个很棒的功能是,你可以打开一个与项目配套的Python解释器。这意味着你可以用它来分析数据库里的对象,还可以在你的项目上执行任何Python命令。我觉得这对Django开发来说非常重要。你可以在项目目录下用这个命令来启动它:
$ python manage.py shell
我刚开始开发一个新项目,但不知道为什么这个命令行工具(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'
提前谢谢你的帮助!
2 个回答
7
IPython 0.11 版本的接口和之前的版本不一样,最新的 Django 版本已经对此进行了修复。
如果你使用的是较旧的 Django 版本,可以选择使用 IPython 0.10,这个版本是可以正常工作的:
pip install ipython==0.10
12
看起来IPython的安装有点问题。你可以试着用下面的命令启动普通的Python环境:
./manage.py shell --plain
这样就可以启动标准的Python环境,而不是IPython。如果这样能正常工作,那就可以考虑把IPython完全卸载掉,然后再重新安装一次。