You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

开发虚拟OS时遇AttributeError:boot模块无bootup属性

Fixing AttributeError: module 'boot' has no attribute 'bootup'

Let's break down what's going wrong here and fix it step by step:

1. Circular Import Problem

You’ve hit a classic circular import issue: boot.py imports Run, and Run.py imports boot. When Python loads these modules, it creates a partial boot module object for Run.py before the bootup function is even defined in boot.py. That’s exactly why you’re seeing the "no attribute 'bootup'" error.

2. Additional Scope & Function Call Issues

  • In Run.py, the run variable inside main() is a local variable, not the global one you defined at the top. So Run.run stays stuck at 0 forever.
  • You’re referencing boot.bootup instead of actually calling the function (you need parentheses: boot.bootup()).
  • In boot.py, you’re calling bootup() without passing the required run parameter—this would throw another error once the import issue is fixed.

Corrected Code

boot.py

# Imports
# Removed circular import of Run to fix loading issues
# Variables
name = "PyOS"
version = 1
creator = "© Dragon Softwares"

def bootup(run_status):
    if run_status == 0:
        error()
    else:
        start()

def start():
    print("Starting PyOS")
    print("Version ", version)

def error():
    print("Please Run 'Run.py' To bootup the system")

# Removed auto-execution of bootup() - let Run.py trigger it

Run.py

# Imports
import time
import boot

# Variables
run = 0

def main():
    global run  # Declare we're modifying the top-level run variable
    run = 1
    time.sleep(0.1)
    boot.bootup(run)  # Properly call the bootup function with the run status

if __name__ == "__main__":
    main()  # Only run main when Run.py is executed directly

Explanation of Fixes

  • Eliminated circular import: boot.py no longer imports Run—instead, we pass the run status directly as an argument to bootup().
  • Fixed variable scope: Added global run in main() to modify the top-level variable instead of creating a local one.
  • Proper function execution: Changed boot.bootup to boot.bootup(run) to actually run the function.
  • Clean entry point: Added if __name__ == "__main__": to ensure main() only runs when you execute Run.py directly (standard practice for Python entry scripts).
  • Fixed missing parameter: bootup() now receives the run_status argument it expects.

内容的提问来源于stack exchange,提问作者Dragon Softwares

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:08:25