Import Error Caused by Error of and Error file multiple levels down #11642
-
This is the 2nd time I've run into this issue so thought I'd share. Before I detail the issue, you should understan a couple of things I've done with my uPython programming on my PICO W.
Here is the problem. I was testing a change and suddenly I was not able to import 'boot_x()' from BOOT_X.MPY. I then tried to import the whole BOOT_X which did not work. The actual errors reported by uPython from running BOOT.PY
The problem? 'boot_x()' was importing a revised 'set_rtc()' from SET_RTC.MPY. This function imports 'SET_RTC_PARAMS.PY'. I had made an incorrect change in this file. Here is the error file.
I had cut and pasted the reference 'params.retry_time' in SET_RTC.PY to SET_RTC_PARAMS.PY' without removing the 'params.' prefix. It was the 'params.retry_time' that was causing the problem running BOOT.PY. Changing 'params.retry_time' to 'retry_time' solved the problem. It took me awhile to ask myself 'what had changed?' when the problem reported was no where need the change was 3 import levels away. Hope this helps someone in the future. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
@DS256 Can you make a simple example to demonstrate this and post the full code here. I tried to replicate it here, but got the expected result. I have the following boot.py from boot_x import boot_x
boot_x() boot_x.py import foo
def boot_x():
print("hello") foo.py 1/0 boot_x.py and foo.py are compiled to .mpy before being copied to the device. When I do a reset, I see
If however I now do the following at the REPL:
I see But I don't think it sounds like you're doing this at the REPL? |
Beta Was this translation helpful? Give feedback.
-
Hi @jimmo . Here's a demonstration Here are my programs.
No need to compile to get the error.
Changing 'params.b' to 'b' in 'boot_x_params.py' produces:
Hope this clarfies |
Beta Was this translation helpful? Give feedback.
Because boot.py will now successfully import boot_x at actual boot time.
It does (see my example). I suspect you're not seeing it in Thonny for some reason.
Just for completeness, here's your exact example using the official tools. First shows the contents of the three files on the device, and the error message being shown at boot time.