`Camelot` 由于 Ghostscript 没有正确的 arm64 架构而给出错误

问题描述 投票:0回答:1

我正在尝试使用 python 包

camelot
但出现以下错误,我知道这与我正在使用的 M1 mac 有关:

>>> import camelot
>>> import pandas
>>> data = camelot.read_pdf('path/to/pdf.pdf')
        Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/camelot/ext/ghostscript/_gsprint.py", line 260, in <module>
    libgs = cdll.LoadLibrary("libgs.so")
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ctypes/__init__.py", line 460, in LoadLibrary
    return self._dlltype(name)
           ^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ctypes/__init__.py", line 379, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: dlopen(libgs.so, 0x0006): tried: 'libgs.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibgs.so' (no such file), '/usr/lib/libgs.so' (no such file, not in dyld cache), 'libgs.so' (no such file), '/usr/lib/libgs.so' (no such file, not in dyld cache)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/camelot/io.py", line 113, in read_pdf
    tables = p.parse(
             ^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/camelot/handlers.py", line 173, in parse
    t = parser.extract_tables(
        ^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/camelot/parsers/lattice.py", line 402, in extract_tables
    self._generate_image()
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/camelot/parsers/lattice.py", line 211, in _generate_image
    from ..ext.ghostscript import Ghostscript
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/camelot/ext/ghostscript/__init__.py", line 24, in <module>
    from . import _gsprint as gs
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/camelot/ext/ghostscript/_gsprint.py", line 268, in <module>
    libgs = cdll.LoadLibrary(libgs)
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ctypes/__init__.py", line 460, in LoadLibrary
    return self._dlltype(name)
           ^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ctypes/__init__.py", line 379, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: dlopen(/Users/adrumm/lib/libgs.dylib, 0x0006): tried: '/Users/adrumm/lib/libgs.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/adrumm/lib/libgs.dylib' (no such file), '/Users/adrumm/lib/libgs.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/usr/local/Cellar/ghostscript/10.02.1/lib/libgs.10.02.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/Cellar/ghostscript/10.02.1/lib/libgs.10.02.dylib' (no such file), '/usr/local/Cellar/ghostscript/10.02.1/lib/libgs.10.02.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

我认为这与之前的问题是同一个问题,但是对该问题的唯一回答没有帮助,因为我已经安装了arm64 Python。

采取的步骤:

  • brew install ghostscript
  • 检查 Ghostscript 是否已按照 软件包文档安装 确认已安装
  • 无论是在虚拟环境中,都会出现同样的问题

这是否可以修复?

python arm64 python-camelot
1个回答
0
投票

Siguza 的评论正确指出了brew 的问题。如果其他人发现自己处于类似情况,我将按照以下方式解决问题:

  1. brew config
    以确认我正在使用x86_64brew

  2. here找到的.pkg文件安装brew(我忘记检查arm64brew是否已经安装)

  3. 将arm64 brew 设置为默认值:

    eval "$(/opt/homebrew/bin/brew shellenv)"
    - source

  4. 创建一个链接,在其中

    camelot
    查找 Ghostscript,如此处

    所述
    mkdir -p ~/lib
    ln -s "$(brew --prefix gs)/lib/libgs.dylib" ~/lib
    
© www.soinside.com 2019 - 2024. All rights reserved.