libarchive的release notes状态指出,由于MacOS中包含了旧版本的libarchive,因此他们建议更改LD_LIBRARY_PATH以指向libarchive的最新副本的位置。

我已使用此代码尝试实现该目标,但是运行脚本时收到错误消息。

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


错误:

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


我在任何地方都找不到很好的答案。

最佳答案

从工具文档尚不清楚,但是基于线程:https://github.com/dsoprea/PyEasyArchive/issues/16我将另一个环境变量设置为可以找到基础c库的位置。就我而言,它是通过自制软件放在我的Mac上的。

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

import libarchive.public


为我工作。

关于python - 如何正确导入最新的libarchive以在Mac OS上使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47800903/

10-12 20:16