Python rarfile package: fail to open files

孤者浪人 提交于 2021-02-07 13:20:32

问题


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

回答1:


Now you need to install unrar for Ubuntu/Linux:

sudo apt-get install -y rar unrar

or the following for MacOS:

brew install unrar


来源:https://stackoverflow.com/questions/37737850/python-rarfile-package-fail-to-open-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!