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 Answer
Reset to default 0Normally 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
版权声明:本文标题:micropython - Getting a syntax error when importing machine module on raspberry pi pico - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743992630a2572427.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
/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