I’m currently working through Mission 4: Objective 2 (Hover) in CodeAIR and have run into an issue that I’m unable to resolve.
In Objective 1, the safety.py file appeared to load correctly, and I was able to proceed without any errors. However, in Objective 2, I am now receiving the following error:
ImportError: no module named 'safety'
This is confusing because the code still includes:
from safety import *
What I’ve tried so far:
Re-running the program multiple times
Executing the code directly from the console
Logging out and back into the platform
Verifying that the code matches the previous objective
Despite these attempts, the issue persists.
Has anyone else encountered this problem in Mission 4, Objective 2? Is there a step I may be missing related to how safety.py is loaded or referenced between objectives?
Any guidance or troubleshooting suggestions would be greatly appreciated. Thank you in advance for your support!
That’s a common stumbling point when moving between these two objectives — the safety.py module needs to be “installed” on your CodeAIR’s filesystem before other programs can import it.
Here’s how it works: in Objective 1 (Modular), when you click the RUN button on the safety.py file, CodeSpace persists that file to CodeAIR’s flash storage. That’s what makes it available for import in Objective 2 and beyond.
A few things to try:
Go back to Objective 1 and make sure you open and RUN the safety.py file directly (not just view it). You should see “Loaded safety.py” appear in the Console panel at the bottom. That confirms it was saved to the device.
Check that your CodeAIR is connected via USB when you run it — the file needs to actually transfer to the device’s filesystem.
After running safety.py, switch to Objective 2 and try running the Hover code again. The from safety import \* line should now find the module.
If it still doesn’t work, try the Reboot and Reload procedure: unplug the USB cable, disconnect the battery, click Chrome’s Reload button, then plug back in and make sure the power switch is ON. Then re-run safety.py from Objective 1 before attempting Objective 2 again. More details here: CodeAIR Troubleshooting
The key takeaway is that any .py file you RUN in CodeSpace gets saved to CodeAIR’s flash — but you do need to run it at least once for it to be there.
Hope that gets you flying! Let us know how it goes.