Django shell无法工作?

0 投票
2 回答
919 浏览
提问于 2025-04-18 08:38

当我启动django的命令行时,出现了内存错误!我在一个共享主机上,没有管理员权限。虽然我不能安装Ipython,但我还是需要这个命令行。

$ python manage.py shell
Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_manager(settings)
  File "/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/django/core/management/base.py", line 218, in execute
    output = self.handle(*args, **options)
  File "/django/core/management/base.py", line 347, in handle
    return self.handle_noargs(**options)
  File "/django/core/management/commands/shell.py", line 26, in handle_noargs
    import IPython
  File "/usr/lib64/python2.7/site-packages/IPython/__init__.py", line 58, in <module>
    __import__(name,glob,loc,[])
  File "/usr/lib64/python2.7/site-packages/IPython/Shell.py", line 30, in <module>
    import ctypes
  File "/usr/lib64/python2.7/ctypes/__init__.py", line 555, in <module>
    _reset_cache()
  File "/usr/lib64/python2.7/ctypes/__init__.py", line 279, in _reset_cache
    CFUNCTYPE(c_int)(lambda: None)
MemoryError

2 个回答

0

请检查一下你的 /tmp 目录的设置。这个目录是否设置了粘滞位(sticky bit)?你可以通过运行命令 ls -ltrd /tmp 来查看,输出应该类似下面这样:

# ls -ltrd /tmp drwxrwxrwt 6 root root 4096 Feb 5 16:43 /tmp

如果 /tmp 是特别挂载的,你也可以尝试重新挂载它(这需要你有管理员权限)。我之前的 /tmp 目录有点问题,所以我把它卸载了,然后重新创建了一个新的 /tmp 目录。之后,我的应用程序就不再出现之前的错误了。

2

你可以使用 --plain 这个选项。

也许这个回答对你有帮助:Python/Django 的命令行界面无法启动

撰写回答