删除了__pycache__和__init__.py

时间:2013-11-11 21:49:58

标签: python django python-3.x

  • Django 1.6
  • Ubuntu 12.04
  • Python 3.2.3

意外删除了Django应用的__pycache__文件夹&它的__init__.py文件,它崩溃了Django。当我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

1 个答案:

答案 0 :(得分:3)

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

另一方面,__init__.py文件是使目录成为模块的原因。如果它最初为空,只需在agepct目录中重新创建它以使导入再次起作用。请注意,__init__.py 不在<{1}}目录中。

如果__pycache__不仅仅是一个空的'make this a package'文件,那么你必须从头开始重新创建该代码或从备份中恢复该文件。