最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

micropython - Getting a syntax error when importing machine module on raspberry pi pico - Stack Overflow

programmeradmin2浏览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.

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.

发布评论

评论列表(0)

  1. 暂无评论