Python rarfile 包:无法打开文件 [英] Python rarfile package: fail to open files

查看:119
本文介绍了Python rarfile 包:无法打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图在 Python 中使用 rarfile 库归档 .rar 文件,但它一直说无法打开".我使用的是 Mac OS X El Capitan,python 2.7.任何帮助将不胜感激,谢谢.

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.

原始代码:

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

错误信息:

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

推荐答案

现在你需要为 Ubuntu/Linux 安装 unrar:

Now you need to install unrar for Ubuntu/Linux:

sudo apt-get install -y rar unrar

或以下适用于 MacOS:

or the following for MacOS:

brew install unrar

这篇关于Python rarfile 包:无法打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆