2010-01-16 49 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