Search code examples
pythonpython-3.xgoogle-colaboratoryunzip7zip

Unzipping .7z File on Google Colab


I have a Zip file named 'mathoverflow.net.7z' in my google drive which I have loaded to colab using the given code. But, when I try to unzip it I get an error. Please suggest a way to rectify this.

This is my code:

!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

downloaded = drive.CreateFile({'id':'15h0f8p9n6OG1B796q-gbP5oXstCuOcDM'})
downloaded.GetContentFile('mathoverflow.net.7z')

Till this it works fine. But when I run this I get the following error.

!unzip mathoverflow.net.7z

Archive: mathoverflow.net.7z End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive. unzip: cannot find zipfile directory in one of mathoverflow.net.7z or mathoverflow.net.7z.zip, and cannot find mathoverflow.net.7z.ZIP, period.


Solution

  • You can use 7z instead. It's already pre-installed in Colab

    !7z e mathoverflow.net.7z