import adafruit_circuitplayground could not be resolved

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
chuck_untulis
 
Posts: 127
Joined: Mon Jun 20, 2011 11:54 pm

import adafruit_circuitplayground could not be resolved

Post by chuck_untulis »

I have this simple code and I can not figure out why I keep getting double red flashes. I have downloaded the latest bundle and I moved
the latest files (as far as I can tell). Specifically: D:\lib\adafruit_circuitplayground\circuit_playground_base.mpy and other mpy files including bluefruit.mpy and express.mpy. I have tried different sets of code and multiple boards.
I thought there might be some bad characters, neither Mu or Visual Studio Code have complained. I do not trust Mu because it does weird stuff including hanging when I was trying to use it last( I had to reboot to get it to go away). I keep wondering why it is recommended when it is so flakey.

The code:

Code: Select all

from adafruit_circuitplayground import cp

while True:
    if cp.button_a:
        cp.start_tone(262)
    elif cp.button_b:
        cp.start_tone(400)
    else:
        cp.stop_tone()
what am I missing?

User avatar
danhalbert
 
Posts: 4688
Joined: Tue Aug 08, 2017 12:37 pm

Re: import adafruit_circuitplayground could not be resolved

Post by danhalbert »

You need to see what is being printed on the REPL, to see the error. Open the Serial window in Mu. More details here: https://learn.adafruit.com/welcome-to-c ... al-console

User avatar
chuck_untulis
 
Posts: 127
Joined: Mon Jun 20, 2011 11:54 pm

Re: import adafruit_circuitplayground could not be resolved

Post by chuck_untulis »

I turned my PC on this morning and from the Mu standpoint, everything seems to be working but when I open the REPL, I see the following:

]0;🐍code.py | 8.0.4\]0;🐍code.py | 8.0.4\]0;🐍code.py | 8.0.4\

and it is unresponsive? If I exit Serial and reenter it, I am back to the same strange information. If I do a Ctrl-C it goes back to the normal REPL interface/interaction. I can put code in and it accepts it?

Visual Studio Code (VSC) still underlines adafruit_circuitplayground and says that it could not be resolved. I can change the code.py and store it back on the circuitplayground and the updated code works.

I can go back to doing coding so you can probably close this. I would welcome any suggestions about how to get rid of the weird output in Mu and why VSC can't resolve "import adafruit_circuitplayground could not be resolved"

Thanks
Chuck

User avatar
danhalbert
 
Posts: 4688
Joined: Tue Aug 08, 2017 12:37 pm

Re: import adafruit_circuitplayground could not be resolved

Post by danhalbert »

The weird output in the Mu serial window is the "status bar". It has escape codes in it that change the title of a terminal window. Mu normally ignores this, but if Mu opens the connection late you may see part of it.You can just ignore it, or you can turn it off: https://docs.circuitpython.org/en/lates ... .StatusBar.

The "not resolved" error is just VSCode not knowing about the Adafruit libraries. It is not really an error in the program. There are ways to inform VSCode about the libraries, but I am unfamiliar with that. Some people in our discord (https://adafru.it/discord, channel #help-with-circuitpython) may be able to help.

User avatar
chuck_untulis
 
Posts: 127
Joined: Mon Jun 20, 2011 11:54 pm

Re: import adafruit_circuitplayground could not be resolved

Post by chuck_untulis »

Thanks very much for the clarification on both issues, but...

I went back and tried loading some PWM code (provided by ChatGPT Plus) and ran into a related error to the earlier one and I ended up with the red flashing lights. When I went into the REPL and loaded the import by hand, I see this
>>> from adafruit_circuitplayground import cp
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'adafruit_circuitplayground'

on the board:
Directory: D:\lib\adafruit_circuitplayground


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 3/25/2023 9:47 PM 1256 bluefruit.mpy
-a---- 3/25/2023 9:47 PM 4660 circuit_playground_base.mpy
-a---- 3/25/2023 9:47 PM 753 express.mpy
-a---- 3/25/2023 9:47 PM 175 __init__.mpy

I was expecting to see just a circuit_playground.mpy.

Now I assume that the adafruit_circuitplayground in the import is pointing to the directory in lib and not the mpy files?

I went back to some previous code, saved it to the board and it ran, but when I tried again to do an insert "from adafruit_circuitplayground import cp" by hand Iin the REPL I get the same error message as earlier even though the code is running?

>>> from adafruit_circuitplayground import cp
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'adafruit_circuitplayground'
>>>

Am I still missing something or doing something wrong?

User avatar
danhalbert
 
Posts: 4688
Joined: Tue Aug 08, 2017 12:37 pm

Re: import adafruit_circuitplayground could not be resolved

Post by danhalbert »

Now I assume that the adafruit_circuitplayground in the import is pointing to the directory in lib and not the mpy files?
An `import` can import a single .py or .mpy file, called a "module", or it can import a Python "package". A package is a directory whose name you use in an import statement. If you just import that package, it runs what is in `__init__.py`.

Could you tell me which board you are using? Is it a Circuit Playground Express or Circuit Playground Bluefruit? Are there any other boards plugged in? Just to make sure, is the D: drive CIRCUITPY ?

User avatar
chuck_untulis
 
Posts: 127
Joined: Mon Jun 20, 2011 11:54 pm

Re: import adafruit_circuitplayground could not be resolved

Post by chuck_untulis »

Thanks again.

Board is Circuit Playground Express

I also had a Trellis plugged and when I removed it the, REPL in Mu stopped complaining.
I then plugged them both in and generated the error again in the Mu REPL.

The D drive is CIRCUITPY

User avatar
danhalbert
 
Posts: 4688
Joined: Tue Aug 08, 2017 12:37 pm

Re: import adafruit_circuitplayground could not be resolved

Post by danhalbert »

Having two boards plugged in at once can be confusing to Mu. Make sure that lib/adafruit_circuitplayground is on the CPX (Circuit Playground Express) CIRCUITPY. Is it possible you might have copied it to the NeoTrellis as well?

User avatar
danhalbert
 
Posts: 4688
Joined: Tue Aug 08, 2017 12:37 pm

Re: import adafruit_circuitplayground could not be resolved

Post by danhalbert »

Also note that the adafruit_circuitplayground library is compiled in to the firmware on the CPX. So you don't even need to put it in the lib directory. If you can't import it, I'm thinking that you might have been talking to the other board instead of the CPX.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”