Python rarfile package: fail to open files

2024/11/15 20:37:01

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

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://en.xdnf.cn/q/71748.html

Related Q&A

Sublime Text 3 Python Interactive Console? [duplicate]

This question already has answers here:Cant send input to running program in Sublime Text(5 answers)Closed 7 years ago.I have been using a lot of sublime text 3 to write python. However, whenever a pro…

Is there any value to a Switch / Case implementation in Python?

Recently, I saw some discussions online about how there is no good "switch / case" equivalent in Python. I realize that there are several ways to do something similar - some with lambda, som…

Replacing the existing MainWindow with a new window with Python, PyQt, Qt Designer

Im new to Python GUI programming Im have trouble making a GUI app. I have a main window with only a button widget on it. What i want to know is how to replace the existing window with a new window when…

Using LaTeX Beamer to display code

Im using the following LaTeX code in a Beamer presentation:\begin{frame}\begin{figure}\centering\tiny\lstset{language=python}\lstinputlisting{code/get_extent.py}\end{figure} \end{frame}Is it possible t…

Python metaclass and the object base class

After reading the excellent SO post, I tried crafting a module level metaclass:def metaclass(future_class_name, future_class_parents, future_class_attrs):print "module.__metaclass__"future_cl…

Is this the equivalent of a copy constructor in Python?

Im reviewing some old python code and came accross this pattern frequently:class Foo(object):def __init__(self, other = None):if other:self.__dict__ = dict(other.__dict__)Is this how a copy constructor…

Fabric error No handlers could be found for logger paramiko.transport

Im not sure why Im getting this error thats terminating my connection. I updated paramiko-1.7.6 from 1.7.5 via easy_install.Im trying to setup Fabric to upload my Django app to my server. The error see…

How to mix unbalanced Datasets to reach a desired distribution per label?

I am running my neural network on ubuntu 16.04, with 1 GPU (GTX 1070) and 4 CPUs.My dataset contains around 35,000 images, but the dataset is not balanced: class 0 has 90%, and class 1,2,3,4 share the …

Is there a way to prevent pandas to_json from adding \?

I am trying to send a pandas dataframe to_json and I am having some issues with the date. I am getting an addtional \ so that my records look like Updated:09\/06\/2016 03:09:44. Is it possible to not…

Convert SQL into json in Python [duplicate]

This question already has answers here:return SQL table as JSON in python(15 answers)Closed 8 years ago.I need to pass an object that I can convert using $.parseJSON. The query looks like this:cursor.e…