1

几个小时以来,我一直在为此挠头。

我一直很高兴地在测试服务器上拉我的回购。该项目有很多提交。我想从我的 repo 中清除所有 .pyc 文件,所以在我的 master 中删除它们并将 *.pyc 添加到 .gitignore。那是对最后一次提交的唯一更改。

现在,当我拉到测试服务器时,Django 导入失败。但是,该模块在那里,除了 .pyc 删除之外没有其他更改。所以这个错误基本上是假的。

如果我重新添加 .pyc 文件,它会再次正常工作。

任何人都可以对此有所了解吗?

编辑:

这是回溯:

Traceback (most recent call last):
File "./manage.py", line 14, in <module>
  execute_manager(settings)
File "/home/galadarwin/.virtualenvs/datazone/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
  utility.execute()
File "/home/galadarwin/.virtualenvs/datazone/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/galadarwin/.virtualenvs/datazone/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
  self.execute(*args, **options.__dict__)
File "/home/galadarwin/.virtualenvs/datazone/lib/python2.7/site-packages/django/core/management/base.py", line 209, in execute
  translation.activate('en-us')
File "/home/galadarwin/.virtualenvs/datazone/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 100, in activate
  return _trans.activate(language)
File "/home/galadarwin/.virtualenvs/datazone/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 202, in activate
  _active.value = translation(language)
File "/home/galadarwin/.virtualenvs/datazone/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 185, in translation
  default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/galadarwin/.virtualenvs/datazone/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 162, in _fetch
  app = import_module(appname)
File "/home/galadarwin/.virtualenvs/datazone/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
  __import__(name)
File "/home/galadarwin/.virtualenvs/datazone/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 3, in <module>
  from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
File "/home/galadarwin/.virtualenvs/datazone/lib/python2.7/site-packages/django/contrib/admin/helpers.py", line 3, in <module>
  from django.contrib.admin.util import (flatten_fieldsets, lookup_field,
File "/home/galadarwin/.virtualenvs/datazone/lib/python2.7/site-packages/django/contrib/admin/util.py", line 1, in <module>
  from django.db import models
File "/home/galadarwin/.virtualenvs/datazone/lib/python2.7/site-packages/django/db/__init__.py", line 67, in <module>
  router = ConnectionRouter(settings.DATABASE_ROUTERS)
File "/home/galadarwin/.virtualenvs/datazone/lib/python2.7/site-packages/django/db/utils.py", line 114, in __init__
  raise ImproperlyConfigured('Error importing database router %s: "%s"' % (klass_name, e))
django.core.exceptions.ImproperlyConfigured: Error importing database router JournalRouter: "No module named journal.routers"
4

2 回答 2

1

事实证明,它__init__.py已经作为 .gitignore 中的一个参数出现了。所以我所有的模块都是在没有__init__.py. 虽然这些__init__.pyc文件仍然存在,但它们必须被用作“后备”(我没有意识到 python 这样做了),所以我的错误被混淆了。我的错,但我学到了一些很好的教训。

于 2012-07-24T12:35:55.940 回答
0

要清理 Django .pyc 文件,请在终端中执行一个或所有命令:

$ python manage.py cleanup
$ pyclean .
$ find . -name "*.pyc" -exec rm -f {} \;
$ find . -name \*.pyc -delete
$ python manage.py clean_pyc
于 2018-03-02T10:37:04.653 回答