Notifications
Clear all

Locating missing library

6 Posts
3 Users
0 Likes
1,274 Views
(@ed-naramor)
Active Member
Joined: 2 years ago
Posts: 3
Topic starter  

I am studying the excellent "Raspberry Pi Pico – How to Interface (almost) Everything!" video.  My problem is with the "import machine" statement. This results in the error "ModuleNotFoundError: No module named 'machine'". I have searched for this library using the manage library function under the tools menu in the Thonny IDE I get a lot of results with the word machine in them but not the "machine library" that I need. Can anyone tell me where I can find the " machine" library?


   
Quote
(@davee)
Noble Member
Joined: 3 years ago
Posts: 1432
 

Hi @ed-naramor,

   I have no direct experience of your problem, but I wondered if you had tried Google?

I entered raspberry pi - "ModuleNotFoundError: No module named 'machine'"  into the search box

and found a number of references including:

https://stackoverflow.com/questions/64919030/python-doesnt-see-machine-package

https://pretagteam.com/question/modulenotfounderror-no-module-named-machine

https://rntlab.com/question/thonny-ide-same-interpreter-which-runs-thonny-default-no-module-named-machine/

... and more...

Maybe one of them would help?

Best wishes, Dave


   
ReplyQuote
(@yurkshirelad)
Honorable Member
Joined: 3 years ago
Posts: 475
 

From a quick Google search, it looks like there are two types of Python that could be installed on the Pico, CircuitPython and Micropython. The "machine" package is only available on Microython. I haven't watched that video, but which Python does it use?

https://forums.raspberrypi.com/viewtopic.php?t=314090


   
ReplyQuote
(@ed-naramor)
Active Member
Joined: 2 years ago
Posts: 3
Topic starter  

I realized that I had to select the correct interpreter . I went to "select interpter" under the Thonny Run menu and selected MicroPython (Raspberry Pi Pico). I then rebooted The Pico and pressed F5 run the script.
I no longer have the missing machine library error but I got an error regarding the ssd1306 library. I then went to "manage packages" under the Thonny Tools menu. A search for ssd1306 and installed it. There were multiple ssd1306 libraries listed and I selected the first one which looked the most reasonable. Now I'm getting the following error:

Traceback (most recent call last):
File "<stdin>", line 16, in <module>
File "/lib/ssd1306.py", line 110, in __init__
File "/lib/ssd1306.py", line 36, in __init__
File "/lib/ssd1306.py", line 71, in init_display
File "/lib/ssd1306.py", line 115, in write_cmd
OSError: [Errno 5] EIO

Traceback (most recent call last):
File "D:\Users\ednar\AppData\Local\Programs\Thonny\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "D:\Users\ednar\AppData\Local\Programs\Thonny\lib\site-packages\thonny\workbench.py", line 995, in dispatch
handler()
File "D:\Users\ednar\AppData\Local\Programs\Thonny\lib\site-packages\thonny\running.py", line 411, in cmd_run_current_script
self.execute_current("Run")
File "D:\Users\ednar\AppData\Local\Programs\Thonny\lib\site-packages\thonny\running.py", line 372, in execute_current
self.execute_editor_content(command_name, self._get_active_arguments())
File "D:\Users\ednar\AppData\Local\Programs\Thonny\lib\site-packages\thonny\running.py", line 347, in execute_editor_content
["%" + command_name, "-c", EDITOR_CONTENT_TOKEN] + args, [EDITOR_CONTENT_TOKEN]
File "D:\Users\ednar\AppData\Local\Programs\Thonny\lib\site-packages\thonny\shell.py", line 224, in submit_magic_command
self.text.submit_command(cmd_line, ("magic",))
File "D:\Users\ednar\AppData\Local\Programs\Thonny\lib\site-packages\thonny\shell.py", line 408, in submit_command
self._try_submit_input()
File "D:\Users\ednar\AppData\Local\Programs\Thonny\lib\site-packages\thonny\shell.py", line 1089, in _try_submit_input
self._submit_input(submittable_text)
File "D:\Users\ednar\AppData\Local\Programs\Thonny\lib\site-packages\thonny\shell.py", line 1231, in _submit_input
get_runner().send_program_input(text_to_be_submitted)
File "D:\Users\ednar\AppData\Local\Programs\Thonny\lib\site-packages\thonny\running.py", line 319, in send_program_input
self._proxy.send_program_input(data)
File "D:\Users\ednar\AppData\Local\Programs\Thonny\lib\site-packages\thonny\running.py", line 982, in send_program_input
self._send_msg(InputSubmission(data))
File "D:\Users\ednar\AppData\Local\Programs\Thonny\lib\site-packages\thonny\running.py", line 975, in _send_msg
self._proc.stdin.write(serialize_message(msg) + "\n")
AttributeError: 'NoneType' object has no attribute 'stdin'

This leads me to wonder if I got the correct ssd1306 library. I had tried loading some of the Adafruit libraries but get the message that said this is not look like the correct one. It asked if I wanted to continue a and I said no.

 

 


   
ReplyQuote
(@davee)
Noble Member
Joined: 3 years ago
Posts: 1432
 

Hi @ed-naramor,

   Sorry you are running stuff I am not familiar with, and the error messages without the code is almost impossible, as without installing, etc. all of the code you are trying to run, I don't know what the system was trying to do when it broke down.

---------

However, a quick Google suggested "OSError: [Errno 5] EIO" might be an odd one based on needing a delay after writing to an EEPROM. But then again there might be a thousand different ways of producing that same error number.

https://forum.micropython.org/viewtopic.php?t=4746

There are other IO operations that also take some time to happen before the program can continue. It is usually possible to write code which watches for completion of an operation, but occasionally the only solution is add in a generous 'best guess' wait.

Others in the forum may know more, but I suggest you try Googling the error ... at first glance there are other suggestions to look at including SPI timing and so on.

---------------

Figuring out what code was actually being run when it broke down is the way to try to solve it analytically.

Posting that fragment of code may be useful for someone to suggest an answer.

Good luck. Dave


   
ReplyQuote
(@yurkshirelad)
Honorable Member
Joined: 3 years ago
Posts: 475
 

I don't know if this is related, but is the device connected and recognised?

https://github.com/thonny/thonny/issues/1722


   
ReplyQuote