Python rarfile package: fail to open files
Asked Answered
I

1

6

So I was trying to archive a .rar file using rarfile library in Python, but it keeps saying "failed to open". Am using Mac OS X El Capitan, python 2.7. Any help would be appreciated, thanks.

Original code:

rf = RarFile('test.rar')
rf.extractall()

Error message:

File "Test.py", line 271, in <module>
rf.extractall()

File "/Users/user/Library/Python/2.7/lib/python/site-packages/rarfile.py", line 679, in extractall
self._extract(fnlist, path, pwd)

File "/Users/user/Library/Python/2.7/lib/python/site-packages/rarfile.py", line 1238, in _extract
check_returncode(p, output)

File "/Users/user/Library/Python/2.7/lib/python/site-packages/rarfile.py", line 1961, in check_returncode
raise exc(msg)

rarfile.RarUnknownError: Unknown exit code [1]: bsdtar: Error opening archive: Failed to open '--'
Intricate answered 9/6, 2016 at 23:39 Comment(1)
Self solved this. Writing down the solution in case that anyone in the future come up with the same problem. The reason why Python failed to open files is that it could not find unrar in the environment. Here's a crystal clear step by step instruction on installing unrar on an Mac: appledigg.com/t/….Intricate
P
7

Now you need to install unrar for Ubuntu/Linux:

sudo apt-get install -y rar unrar

or the following for MacOS:

brew install unrar
Pathogenic answered 27/8, 2019 at 19:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.