3

我正在使用 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 ( python setup.py bdist --format=rpm) 并将其作为鸡蛋安装在/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__'

有谁知道解决这个问题的方法?

4

2 回答 2

8

看起来这是Piston 0.2.3的一个已知问题。您可以应用此补丁或仅使用 0.2.2 版,方法是这样安装:

pip install django-piston==0.2.2
于 2011-11-27T01:10:05.330 回答
1

我有同样的问题,不知道是什么原因造成的,但为了解决这个问题,我在设置中取消了我的 INSTALLED_APPS 中的活塞应用程序的注释,它又开始工作了,所以这与加载活塞有关。我将从我的站点包目录中删除活塞并尝试重新加载它,看看是否有帮助。

此外,在试图找到我的问题的答案时,我遇到了一些有类似问题的网站。

该站点描述了与__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/

还有一个我找不到的,提到无法从作为鸡蛋安装的应用程序中正确加载文件。

于 2011-04-22T16:01:35.240 回答