admin管理员组

文章数量:1355564

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.

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.

Share Improve this question asked Mar 30 at 9:27 Jaco MareJaco Mare 1 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
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: micropythonGetting a syntax error when importing machine module on raspberry pi picoStack Overflow