IPython找不到Shell.IPShell类

8 投票
3 回答
3465 浏览
提问于 2025-04-16 07:31

在安装了Django之后,我按照这个教程来玩API。当我运行下面的命令时。

python manage.py shell

我收到了这个错误信息。

  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'

我检查了一下,发现我有Shell.py模块,并且里面有IPShell类。

/Library/Python/2.6/site-packages/IPython/Shell.py

class IPShell:
    """Create an IPython instance."""

这到底是怎么回事呢?我的IPython/Python/操作系统信息如下。

  • Mac OS X 10.6.5
  • Python 2.6.1
  • IPython版本 0.10.1

补充说明

>>> import IPython
>>> IPython.Shell
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'module' object has no attribute 'Shell'
>>> print IPython.__file__
/Library/Python/2.6/site-packages/IPython/__init__.py

问题解决

在ma3和Ignacio的帮助下,我解决了这个问题。

  1. 删除site-package/IPython和site-package/ipython*.egg
  2. 用命令sudo easy_install ipython重新安装IPython
  3. 按照Ignacio提供的链接,对Django的shell.py应用补丁。

        try:
            shell = IPython.InteractiveShell()
        except AttributeError:
            # IPython < 0.11
            # Explicitly pass an empty list as arguments, because otherwise IPython
            # would use sys.argv from this script.
            shell = IPython.Shell.IPShell(argv=[])
        shell.mainloop()
    

3 个回答

2

对于 IPython 0.11.dev 版本,已经修复了这个问题:

from IPython.frontend.terminal.ipapp import IPythonApp
app = IPythonApp(argv=[])
app.start()
3

这里是来自GitHub上django-extensions库的一个官方提交记录:

Django-Extensions GitHub库

你可以通过以下方式来安装它:

$ git clone git://github.com/django-extensions/django-extensions.git
$ cd django-extensions
$ python setup.py install 
7

在2009年8月19日,IPython做了一次更改,把某个名字去掉了,而Django还没有跟上这个变化。所以,这算是Django的一个bug。

补充:

你可以在这里找到相关信息。

撰写回答