'How can unrar a file with python
How can I extract a .zip or .rar file using Python?
Solution 1:[1]
Solution 2:[2]
Solution 3:[3]
After some deep diving, here are my findings:
- RAR is not an free open format and is owned by RARLabs. You must install their DLL or exe first to work with RAR. Some programs like 7zip might already include this with them.
patoolis application that provides uniform command line as wrapper to other external compression applications. Natively, it can only deal with TAR, ZIP, BZIP2 and GZIP without needing external support.pyunpackis Python library that can only deal with zip natively but provides interface topatool.
With this in mind, following things worked for me:
- Make sure 7zip is installed
pip install patool pyunpack
Then to use it,
import pyunpack
pyunpack.Archive(archive_file).extractall(extract_dir)
Solution 4:[4]
Solution 5:[5]
This method only requires having 7zip installed.
Works flawlessly on every system 7zip does.
No python packages needed at all.
import subprocess
subprocess.run('7z x -oOutdir archive.rar')
The subprocess module is comes with python.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | fenceop |
| Solution 2 | |
| Solution 3 | Shital Shah |
| Solution 4 | Community |
| Solution 5 | alexpdev |
