2010-01-16 84 views
6

Django的一个重要特性是您可以打开一个Python解释器设置以用于您的项目。这可用于分析数据库中的对象,并允许在您的项目上执行任何python命令。我发现它对于Django开发非常重要。它使用此命令在项目目录调用:Python/Django shell将无法启动

$ python manage.py 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' 

在此先感谢您的帮助!

+0

你有IPython的安装?它在你的'PYTHONPATH'中吗? – notnoop 2010-01-16 16:26:07

+0

哦,那很好,是django与ipython集成了吗? – shylent 2010-01-16 16:30:31

+1

@shylent,是的,从某种意义上说,如果安装了它,它将使用IPython作为shell。 – 2010-01-16 16:44:05

回答

12

似乎IPython以某种方式安装错误。尝试启动外壳:

./manage.py shell --plain 

启动标准Python shell而不是IPython。如果可行,那么尝试彻底删除IPython并重新安装。

+0

非常感谢!这工作完美。 – danpalmer 2010-01-16 16:50:43

+0

太棒了!一捆谢谢 – 2017-11-17 11:36:59

6

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

对于旧的Django版本,你可以使用IPython的0.10,这不工作:

pip install ipython==0.10 
+1

反对 \t 工作。 但是,当我启动壳,我得到IOError:在当前或提供的目录中找不到File'ipythonrc :.大概写了现有的ipython 11版本和10不再可以读取!? 运行: rm -rf〜/ .ipython/ 似乎要修复。 – brianray 2011-12-07 15:50:40

+2

@brianray:这是可能的,我可以确认'rm -Rf〜/ .ipython /'是一个很好的解决方法。 – vdboor 2011-12-08 18:55:08

+0

谢谢!我正在寻找与django 1.0.4兼容的python版本 – Munhitsu 2012-07-16 18:00:33