使用egg模块时如何同步django-piston模型
我在使用django-piston的时候,运行manage.py syncdb命令时遇到了一个问题:
Traceback (most recent call last):
File "./manage.py", line 13, in <module>
execute_manager(settings)
File "/home/appfirst/django/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
............ lines ommitted ...........
File "/home/appfirst/django/django/utils/translation/trans_real.py", line 176, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/appfirst/django/django/utils/translation/trans_real.py", line 160, in _fetch
apppath = os.path.join(os.path.dirname(app.__file__), 'locale')
AttributeError: 'module' object has no attribute '__file__'
在我的开发环境中,我没有这个问题。因为我把python的路径设置成了包含django-piston的目录。在生产环境中,我是通过编译成rpm格式来安装piston的(python setup.py bdist --format=rpm
),然后把它作为一个egg安装到/usr/lib/python2.6/site-packages/
。这就意味着在开发环境中,我可以这样做:
>>> import piston
>>> piston.__file__
/some/file/path/here
但是在生产环境中,我却遇到了:
>>> import piston
>>> piston.__file__
AttributeError: 'module' object has no attribute '__file__'
有没有人知道有什么解决办法吗?
2 个回答
1
我也遇到过同样的问题,不太清楚是什么原因导致的,但我找到了解决办法:我把设置中的INSTALLED_APPS里的piston应用注释掉,然后它又开始正常工作了,所以问题和加载piston有关。我打算把piston从我的site-packages目录里删除,然后重新加载一下,看看这样是否能解决问题。
另外,在寻找答案的过程中,我发现了一些网站也讨论了类似的问题。
这个网站提到一个和__init__.py
缺失有关的问题。
http://www.willmer.com/kb/2007/12/attributeerror-module-object-has-no-attribute-blah/
这个网站提到循环导入也是一个问题。
http://www.answermysearches.com/python-fixing-module-object-has-no-attribute/333/
还有一个我找不到的网站,提到过从作为egg安装的应用中无法正确加载文件的问题。