0

After loading micropython on my raspberry pi pico and trying to run a simple blink code on thonny or vs code i get the same error which is the following.

>>> import machine
Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "<string>", line 1, in <module>
  File "/lib/machine/__init__.py", line 747
SyntaxError: invalid syntax

And here is the blink code that i tried to run.

from machine import Pin
from utime import sleep

pin = Pin("LED", Pin.OUT)

print("LED starts flashing...")
while True:
    try:
        pin.toggle()
        sleep(1) # sleep 1sec
    except KeyboardInterrupt:
        break
pin.off()
print("Finished.")

When i run a print("hello") on the pico it does work. I have tried loading earlier builds of micro python but it does the same thing.

I tried to run a simple blink program to confirm that my ide and raspberry pi pico was set up correctly.It sucsessfully imports other modules like time but the moment i try to import the machine module it gives a syntax error in the init.py file.

1
  • 1
    The problem is that there is a syntax error in /lib/machine/__init__.py. It is not a problem in the code you have shown (except maybe that you shouldn't have imported that module).
    – mkrieger1
    Commented Mar 30 at 9:48

1 Answer 1

0

Normally there is no problem importing the machine module because it is define in C code in the MicroPython interpreter. However, on your system, MicroPython is finding a file named lib/machine/__init__.py and tring to load that, and it has a syntax error on like 747. Look in your device's filesystem for that file. You should probably just remove or rename the entire machine directory that you have.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.