【问题标题】:Sync django-piston models when using egg module使用 egg 模块时同步 django-piston 模型
【发布时间】:2011-08-09 18:21:57
【问题描述】:

我正在使用 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__'

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

【问题讨论】:

    标签: python django django-piston


    【解决方案1】:

    看起来这是带有活塞 0.2.3 的 known issue。您可以申请 this patch 或直接安装 0.2.2 版:

    pip install django-piston==0.2.2
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,不知道是什么原因造成的,但为了解决这个问题,我在设置中的 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/

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-12-24
        • 2011-08-17
        • 2016-04-10
        • 1970-01-01
        • 1970-01-01
        • 2017-10-09
        • 2011-02-19
        相关资源
        最近更新 更多