我正在尝试使用 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
这是否可以修复?
Siguza 的评论正确指出了brew 的问题。如果其他人发现自己处于类似情况,我将按照以下方式解决问题: