我今天使用git提取了最新的代码,我收到以下错误:
ImportError at / cannot import name Like
这可能与循环导入有关.我检查了回溯:
Traceback: File "/Library/Python/2.7/site-packages/Django-1.4.1-py2.7.egg/django/core/handlers/base.py" in get_response 101. request.path_info) File "/Library/Python/2.7/site-packages/Django-1.4.1-py2.7.egg/django/core/urlresolvers.py" in resolve 298. for pattern in self.url_patterns: File "/Library/Python/2.7/site-packages/Django-1.4.1-py2.7.egg/django/core/urlresolvers.py" in url_patterns 328. patterns = getattr(self.URLconf_module,"urlpatterns",self.URLconf_module) File "/Library/Python/2.7/site-packages/Django-1.4.1-py2.7.egg/django/core/urlresolvers.py" in URLconf_module 323. self._URLconf_module = import_module(self.URLconf_name) File "/Library/Python/2.7/site-packages/Django-1.4.1-py2.7.egg/django/utils/importlib.py" in import_module 35. __import__(name) File "/Users/Desktop/python/mystuff/Project/Project/urls.py" in <module> 7. admin.autodiscover() File "/Library/Python/2.7/site-packages/Django-1.4.1-py2.7.egg/django/contrib/admin/__init__.py" in autodiscover 29. import_module('%s.admin' % app) File "/Library/Python/2.7/site-packages/Django-1.4.1-py2.7.egg/django/utils/importlib.py" in import_module 35. __import__(name)
在那里看到的唯一代码可能是导致问题的是urls.py.那里有以下代码:
from django.contrib import admin admin.autodiscover()
所以在这个时候,我注意到我们以前写过的admin.py文件在最新的合并中被删除,但是admin.pyc仍然存在.删除.pyc文件继续修复循环导入错误,现在似乎工作正常.
我的问题是:这里究竟发生了什么? Git被配置为忽略所有pyc文件,所以在合并之后,即使删除了.py,.pyc也被卡住了.但是,如果.py本身被删除,python应该不够聪明,不要尝试调用.pyc中的任何编译代码?