How to correctly import latest libarchive for use on Mac OS

1.5k views Asked by At

The release notes for libarchive state that because of an older version of libarchive being included within MacOS they recommend changing LD_LIBRARY_PATH to point towards the location of the recent copy of libarchive.

I've used this code to try and achieve that but I get an error message when I run the script.

import os

print os.environ.get('LD_LIBRARY_PATH') #Check what the current path is 

os.environ['LD_LIBRARY_PATH'] = '/Library/Python/2.7/site-packages/'
print os.environ.get('LD_LIBRARY_PATH') #Check the variable has been set 

import libarchive.public

Error:

None
/Library/Python/2.7/site-packages/
Traceback (most recent call last):
  File "scratch.py", line 8, in <module>
    import libarchive.public
  File "/Library/Python/2.7/site-packages/libarchive/public.py", line 1, in <module>
    from libarchive.adapters.archive_read import \
      File "/Library/Python/2.7/site-packages/libarchive/adapters/archive_read.py", line 7, in <module>
    import libarchive.calls.archive_read
  File "/Library/Python/2.7/site-packages/libarchive/calls/archive_read.py", line 17, in <module>
c_archive_read_support_filter_all = libarchive.archive_read_support_filter_all
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 378, in __getattr__
func = self.__getitem__(name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 383, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(0x7fb08b741000, archive_read_support_filter_all): symbol not found

I cant find a great answer to this anywhere out there.

1

There are 1 answers

0
Colleen Fallaw On BEST ANSWER

It is not clear from the tool documentation, but based on a thread: https://github.com/dsoprea/PyEasyArchive/issues/16 I set another environment variable to the place where the underlying c library could be found. In my case, it was put there by homebrew on my mac.

os.environ['LA_LIBRARY_FILEPATH']='/usr/local/opt/libarchive/lib/libarchive.dylib'

import libarchive.public

worked for me.