How to Install Python Bindings for unrar

This guide provides a straightforward walkthrough for installing and configuring the Python bindings for unrar. While the Python package itself can be installed quickly using pip, the underlying binding relies on the official UnRAR shared C++ library. Below are the steps to install the Python wrapper, download and configure the required native library across different operating systems, and verify that the setup works properly.

Step 1: Install the Python Package

Install the unrar Python library from PyPI using pip:

pip install unrar

The package acts as a Python wrapper around the UnRAR C++ dynamic library. Running pip install unrar alone is not enough; you must also provide the compiled library (.dll, .so, or .dylib) on your system.


Step 2: Install the UnRAR Shared Library

The native UnRAR library must be installed and accessible via your system's dynamic linker or an environment variable.

On Ubuntu / Debian

On Debian-based systems, download and build the dynamic library source directly from RARLAB:

# Update package list and install build tools
sudo apt update
sudo apt install build-essential wget

# Download and extract the source
wget https://www.rarlab.com/rar/unrarsrc-6.2.3.tar.gz
tar -xvf unrarsrc-6.2.3.tar.gz
cd unrar

# Build the shared library and install it
make lib
sudo make install-lib

This compiles libunrar.so and places it into /usr/lib, making it automatically discoverable by Python.

On macOS

You can build the library using Homebrew tools:

# Download and extract the source
curl -O https://www.rarlab.com/rar/unrarsrc-6.2.3.tar.gz
tar -xvf unrarsrc-6.2.3.tar.gz
cd unrar

# Compile the shared library
make lib
sudo install -m 755 libunrar.so /usr/local/lib/libunrar.so

On Windows

  1. Download the UnRAR source or dynamic library package from the official RARLAB website.
  2. Locate the compiled unrar.dll file (often found in the UnRARDLL.exe self-extracting archive or compiled from source).
  3. Copy unrar.dll (for 32-bit Python) or x64\UnRAR64.dll renamed to unrar.dll (for 64-bit Python) to C:\Windows\System32.

Step 3: Configure the Library Path (Optional)

If you cannot install the library to standard system directories, set the UNRAR_LIB_PATH environment variable to point to the file directly.

On Linux/macOS:

export UNRAR_LIB_PATH="/path/to/libunrar.so"

On Windows (PowerShell):

[System.Environment]::SetEnvironmentVariable('UNRAR_LIB_PATH', 'C:\path\to\unrar.dll', 'User')

Step 4: Verify the Installation

To verify that the binding connects properly with the library, open a Python shell and run:

from unrar import rarfile

# If the library is found, this will execute without an UnrarException
archive = rarfile.RarFile("example.rar")
print(archive.namelist())

If the dynamic library is missing or improperly mapped, Python will raise unrar.cfile.UnrarException: Couldn't find path to unrar library. If no error appears, the installation is complete.