How to unzip a zip file in Jupyter/Google Colab?

Muhammad Iqbal bazmi
2 min readMar 18, 2021

The problem is solved after having hours of search over google…

Photo by Huy Pham on Unsplash

I was solving a Deep Learning assignment using Google Colab. I had a dataset of images contained in a different folder for each image in Google drive and for the label of the dataset, I was having a data frame consisting of path and label.

So, I was supposed to use ImageDataGenerator’s method flow_from_dataframe() .

That was the reason that instead of mounting Google drive I downloaded the zip into the RAM of Google Colab using the CurlWget extension(very fast downloading). Because flow_from_dataframe() will take a lot of time to get the image from Google drive.

Now, the problem was to unzip the downloaded zip file in the Google Colab.

How I downloaded the file?

downloaded file

Solution:

Let’s unzip the above file

  1. install patool:
install patool

2. import patool:

import patool as patoolib

3. use patoolib.extract_archive()

extract_archive()

Note: You can unzip almost every type of zipped file.

Thanks!

Subscribe to my Youtube channel to know more about Data Science.

The Data Science course will be started soon on my channel.

Click here! to subscribe and get a notification when I will start this course from absolute scratch.

--

--

Muhammad Iqbal bazmi

A self-taught programmer, Data Scientist and Machine Learning Engineer