【问题标题】:Pyforms AttributeError: ‘module’ object has no attribute ‘start_app’Pyforms AttributeError:“模块”对象没有属性“start_app”
【发布时间】:2017-08-22 08:30:36
【问题描述】:

在我的 Raspberry Pi 3 上安装 pyforms 后,我尝试运行在 readthedocs 上找到的示例,但应用程序抛出了 AttributeError(我尝试了 python2 和 python3)


Python 代码

import pyforms
from   pyforms          import BaseWidget
from   pyforms.Controls import ControlText
from   pyforms.Controls import ControlButton

class SimpleExample1(BaseWidget):

    def __init__(self):
        super(SimpleExample1,self).__init__('Simple example 1')

        #Definition of the forms fields
        self._firstname     = ControlText('First name', 'Default value')
        self._middlename    = ControlText('Middle name')
        self._lastname      = ControlText('Lastname name')
        self._fullname      = ControlText('Full name')
        self._button        = ControlButton('Press this button')


#Execute the application
if __name__ == "__main__":   pyforms.start_app( SimpleExample1 )

错误:

Traceback (most recent call last):
  File "PiControl.py", line 20, in <module>
    if __name__ == "__main__":   pyforms.start_app( SimpleExample1 )
AttributeError: ‘module’ object has no attribute ‘start_app’


编辑:

我尝试使用

手动导入start_app
from pyforms.gui.standaloneManager import start_app

但后来我得到另一个ImportError

Traceback (most recent call last):
  File "PiControl.py", line 4, in <module>
    from   pyforms.gui.standaloneManager import start_app
ImportError: cannot import name 'start_app'

【问题讨论】:

  • 同目录下是否还有其他名为 pyforms 的文件?
  • @AbhishekP 不,PiControl.py 是目录中唯一的文件
  • @Error404,如果手动导入start_app,可以启动应用吗? from pyforms.gui.standaloneManager import start_app。检查您的PYFORMS_MODE 环境变量:就在start_app 之前做:import os; print(os.environ.get('PYFORMS_MODE'))
  • @9dogs PYFORMS_MODE 环境变量未设置,所以我尝试将其设置为GUI,产生相同的结果
  • @9dogs 从pyforms.gui.standaloneManager 导入start_app 产生了一个ImportError(参见更新后的问题)

标签: python pyforms


【解决方案1】:

这是非常奇怪的行为,可能意味着您的安装已损坏。尝试从 repo 安装最新版本:

pip install -U git+https://github.com/UmSenhorQualquer/pyforms.git 
pip install -U git+https://github.com/UmSenhorQualquer/pysettings.git
pip install -U git+https://bitbucket.org/fchampalimaud/logging-bootstrap.git

【讨论】:

    猜你喜欢
    • 2010-11-18
    • 2018-08-28
    相关资源
    最近更新 更多