Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use pyunpack to unpack .7z file?

Im trying to unpack a 7z file but got an error.

This is the code:

from pyunpack import Archive
Archive('E:/Desktop/vnpt2/2_1_0_2841.7z').extractall('E:/Desktop/vnpt2/new')

And this is error:

Traceback (most recent call last):
  File "E:\Desktop\vnpt2\zip.py", line 2, in <module>
    Archive('E:/Desktop/vnpt2/2_1_0_2841.7z').extractall('E:/Desktop/vnpt2/new')
  File "C:\Python27\lib\site-packages\pyunpack\__init__.py", line 90, in extractall
    self.extractall_patool(directory, patool_path)
  File "C:\Python27\lib\site-packages\pyunpack\__init__.py", line 62, in extractall_patool
    raise PatoolError('patool can not unpack\n' + str(p.stderr))
pyunpack.PatoolError: patool can not unpack
patool error: error extracting E:\Desktop\vnpt2\2_1_0_2841.7z: could not find an executable program to extract format 7z; candidates are (7z,7za,7zr),

How can I fix it?

like image 503
Fatworm Avatar asked Jun 07 '18 15:06

Fatworm


People also ask

What can unzip 7z files?

WinZip opens and extracts 7z Compressed Archive Files—and many more formats.

Why can't I open a .7z file?

If you've come across a file that ends in “. 7z”, you're probably wondering why you can't open it. These files, known as “7z” or “7-Zip files,” are archives of one or more files in one single compressed package. You'll need to install an unzipping app to extract files from the archive.


Video Answer


2 Answers

You can instead use the combination of py7zr package and shutil package to unzip 7z file.

Steps

  1. Pip install py7zr

  2. Run the below code:

from py7zr import unpack_7zarchive
import shutil

shutil.register_unpack_format('7zip', ['.7z'], unpack_7zarchive)
shutil.unpack_archive('filename.7z', '/unzip_path')
like image 108
Aeolian7 Avatar answered Oct 20 '22 09:10

Aeolian7


If you are using Mac OS, install 7zip with command

brew install p7zip

On windows download and install 7zip from https://www.7-zip.org/download.html

Then update the PATH variable to point the directory containing 7za.exe

like image 39
Nikhil George Avatar answered Oct 20 '22 09:10

Nikhil George