How to import modules with PyCharm and MicroPython?

I decided to test PyCharm with Raspberry Pi Pico. I created a simple test program with MicroPython. Everything seems to work when all the code is in the main file called 'main.py'. After that, I decided to create another module called 'my_sensor.py'. However, it seems that the module is not imported even if it is in the same directory than the main file:

Traceback (most recent call last):
  File "main.py", line 7, in <module>
ImportError: no module named 'my_sensor'
MicroPython v1.18 on 2022-01-17; Raspberry Pi Pico with RP2040
Type "help()" for more information.

It seems that the module is not included when the application is uploaded to Raspberry Pi Pico. I do not understand why. I cannot see any errors or warnings in the IDE.

2 comments
Comment actions Permalink

Hi, are you able to upload and run your code from the terminal without using the IDE? If so, feel free to submit an issue to https://github.com/vlasovskikh/intellij-micropython/issues

0
Comment actions Permalink

Hi, i had the same Problem. It seems to be the case that you have to flash each file seperately onto the Pico. In your case, right click on your file in the Project Window and chose Run 'Flash my_sensor.py' just as you did with your main.py file

0

Please sign in to leave a comment.