Gangmax Blog

Pip Install "libarchive"

libarchive“ is multi-format archive and compression library written in C. It supports a lof of compression formats and archive formats. The full list can be found here.

There is another “libarchive“ pip package written in Python which is a Python wrapper of the C version “libarchive”. You can use this pip package if you want to use Python to manipulate different compression/archive formats.

To install the “libarchive“ Python pip package, you need to install the native C “libarchive” library first if you didn’t have it.

For Debian/Ubuntu:

1
sudo apt-get install libarchive-dev

For Mac:

1
brew install libarchive

Now for Linux, you can run pip to install the Python “libarchive” pip package:

1
pip install libarchive

For Mac, you need one more step to set the “libarchive.dylib” path first, otherwise the installation will fail.

1
2
3
# From: https://github.com/dsoprea/PyEasyArchive/issues/16
export LA_LIBRARY_FILEPATH="/opt/brew/opt/libarchive/lib/libarchive.dylib"
pip install libarchive

Now you should be able to use the Python “libarchive” pip package now. For example:

1
2
3
import libarchive.public
for entry in libarchive.public.file_pour('/Users/auser/log.cpio.gz'):
print(entry)

More code samples can be found here.

Comments