I'm trying to use the python package camelot
but get the following error, which I understand relates to my M1 mac I'm using:
>>> 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'))
I think this is same issue as this prior question, but the sole response to that question does not help as I already have the arm64 Python installed.
Steps taken:
brew install ghostscript
Is this even possible to fix?
The comment from Siguza correctly pointed to the issue being with brew. Here's how I fixed the problem if anyone else finds themselves in similar situation:
Ran brew config
in to confirm I was using x86_64 brew
Install brew from the .pkg file found here (I forgot to check if the arm64 brew was already installed or not though I do not think so)
Set arm64 brew as default: eval "$(/opt/homebrew/bin/brew shellenv)"
- source
Create a link where camelot
looks for Ghostscript as explained here
mkdir -p ~/lib
ln -s "$(brew --prefix gs)/lib/libgs.dylib" ~/lib