How do I manually install a library in Thonny

11.7k Views Asked by At

I want to install this library using Thonny https://github.com/adafruit/Adafruit-uRTC to use a DS3231 with my Raspberry Pi Pico. I cannot install it via the built-in package manager feature for two reasons. The version on PyPi is out of date and apparently buggy, I want to use the latest version. Even if I wanted to use the version on PyPi micropip fails to install it with an opaque and unhelpful error message "micropip returned with error code 1".

I have the source files, they have no dependencies, how can i just install them manually?

1

There are 1 best solutions below

2
On BEST ANSWER

The library you are trying to install is deprecated. Maybe you want a more specific driver like this one. You can just upload it to your board like any other .py file.

Generally to install libraries manually you enter the REPL and type.

>>> import upip
>>> upip.install("NAME OF PACKAGE")

You can also provide a path to the package on your local filesystem. More information can be found here.

>>> import upip
>>> upip.install("NAME OF PACKAGE", "c:\full\path\to\package")

However that is not the optimal method as it injects the module as pure python and can lead to memory allocation errors. The best way is to freeze the module into your firmware. This requires rebuilding the firmware. It is beyond the scope of this answer to explain how to freeze modules and rebuild firmware. There are plenty of article and .PDF resources on the subject.