1
  • 姜戈 1.6
  • Ubuntu 12.04
  • Python 3.2.3

意外删除了 Django 应用程序的__pycache__文件夹及其__init__.py文件,导致 Django 崩溃。当 I 时python3 manage.py runserver,它会立即声称没有名为agepct的模块,即使应用程序的目录存在并且所有文件都在其中(我删除的文件除外)。我清空了垃圾箱,所以我无法取回文件。除了从头开始重新创建整个应用程序之外,有什么方法可以让应用程序再次运行?

这是我尝试时吐出的回溯runserver

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.2/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.2/dist-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.2/dist-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python3.2/dist-packages/django/core/management/base.py", line 280, in execute
    translation.activate('en-us')
  File "/usr/local/lib/python3.2/dist-packages/django/utils/translation/__init__.py", line 130, in activate
    return _trans.activate(language)
  File "/usr/local/lib/python3.2/dist-packages/django/utils/translation/trans_real.py", line 188, in activate
    _active.value = translation(language)
  File "/usr/local/lib/python3.2/dist-packages/django/utils/translation/trans_real.py", line 177, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/usr/local/lib/python3.2/dist-packages/django/utils/translation/trans_real.py", line 159, in _fetch
    app = import_module(appname)
  File "/usr/lib/python3.2/importlib/__init__.py", line 124, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/lib/python3.2/importlib/_bootstrap.py", line 824, in _gcd_import
    raise ImportError(_ERR_MSG.format(name))
ImportError: No module named agepct
4

1 回答 1

3

__pycache__目录是字节编译文件的缓存,将在您导入包时重新构建。

__init__.py另一方面,文件使目录成为模块。如果它最初是空的,只需在agepct目录中重新创建它,导入即可再次工作。请注意,它不会__init__.py在目录中。__pycache__

如果__init__.py不仅仅是一个空的“将此作为一个包”文件,那么您必须从头开始重新创建该代码或从备份中恢复该文件。

于 2013-11-11T21:53:27.917 回答