Trouble unzipping a file on a Raspberry Pi Pico using uzlib


I was wondering if anyone might be able to shed some light on an issue I am having. I am trying to expand a zip file on a raspberry pi pico with micropython and not having much success. I am using the uzlib module, which after some googling seems to be the way to go. However, the code is failing with a -3 error which I believe is something to do with not being able to understand the format of the zip file.

Traceback (most recent call last):
  File "<stdin>", line 20, in <module>
  File "<stdin>", line 10, in unzip
ValueError: -3

The test zip I am using is very simple and was created from the command line using:

touch text.txt
zip text.txt

It also doesn’t work with the third party zip I also ultimately want to use.

The code to unzip the file is as follows:

import uzlib
import os

def unzip(zip_file_path, extract_path):

  with open(zip_file_path, "rb") as zip_file:
    zip_data =

    # Decompress the zip data.
        files = uzlib.decompress(zip_data)
        print("Decompress failed!")

    # Extract the files to the specified extract path.
        for filename, data in files.items():
          with open(os.path.join(extract_path, filename), "wb") as output_file:
        print("Write failed!")

zip_file_path = ""
extract_path = "/tmp"

unzip(zip_file_path, extract_path)

Any ideas or better ways to unzip a file would be gratefully received.

I should probably also say that the files are all in the root dir of the pico.

Hi Andrew,

Looks like zip has a few options available for compression, a good first step might be to manually switch to those and see if the Pico likes any of them:

(Snip taken from a site mirroring the manpage)

Maybe having a full size Pi Zero in the mix talking over serial to a Pico? IME big OS-y stuff like networking and file systems are best handled by microprocessors, but I’m not saying you need to abandon your plan!

Could you share a little more about your project, and what the motivation is? That’ll help us suggest alternative plans of attack.

Thanks for your reply James.

I’ve tried different zip configs with no effect. I’m a bit stumped with this one as all info I have suggests it should work.

With regards to my project, I am wanting to download the latest release of my Pico app via the GitHub api onto the pico directly over wifi, then unzip it and restart the Pico to use the new version. Everything is working except the unzip bit.