在 Google Colab 上解压 .7z 文件

Unzipping .7z File on Google Colab

我的 google 驱动器中有一个名为 'mathoverflow.net.7z' 的 Zip 文件,我已使用给定代码将其加载到 colab。但是,当我尝试解压缩它时,出现错误。请提出纠正此问题的方法。

这是我的代码:

!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')

至此一切正常。但是当我 运行 这样做时,我收到以下错误。

!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.

无法解压缩,您需要其他工具:https://www.simplified.guide/linux/extract-7z-file

我不知道你在 colab 上有安装权限,所以你可能不得不在你自己的机器上安装。

您可以改用7z。它已经预装在 Colab

!7z e mathoverflow.net.7z
!pip install pyunpack
!pip install patool

from pyunpack import Archive
Archive('file_name.7z').extractall('path/to/')