【问题标题】:Python/Django shell won't startPython/Django shell 无法启动
【发布时间】:2023-04-07 13:39:01
【问题描述】:

Django 的一大特色是您可以打开一个 Python 解释器设置以用于您的项目。这可用于分析数据库中的对象,并允许在您的项目上执行任何 python 命令。我发现它对 Django 开发至关重要。使用以下命令在项目目录中调用它:

$ 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'

提前感谢您的帮助!

【问题讨论】:

  • 你安装了 ipython 吗?它在您的PYTHONPATH 中吗?
  • 哦,太好了,那么django和ipython集成了吗?
  • @shylent,是的,从某种意义上说,如果安装了 IPython,它将使用 IPython 作为 shell。

标签: python django shell


【解决方案1】:

IPython 似乎以某种方式安装错误。尝试使用以下命令启动 shell:

./manage.py shell --plain

启动标准 Python shell,而不是 IPython。如果可行,请尝试完全删除 IPython 并重新安装。

【讨论】:

    【解决方案2】:

    IPython 0.11 有一个不同的 API,在最新的 Django 版本中已对此进行了修复。

    对于较旧的 Django 版本,您可以使用 IPython 0.10,它确实有效:

    pip install ipython==0.10
    

    【讨论】:

    • 否决票这行得通。但是,当我启动 shell 时,我得到 IOError: File'ipythonrc' not found in current or provided directory:。可能在现有的 ipython 11 版本上写了 10 不再可以读取!?运行:rm -rf ~/.ipython/ 似乎修复它。
    • @brianray:这是可能的,我可以确认rm -Rf ~/.ipython/ 是一个很好的解决方案。
    • 谢谢!我正在寻找与 django 1.0.4 一起使用的 python 版本
    猜你喜欢
    • 2020-11-23
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-12
    相关资源
    最近更新 更多