Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

RuntimeError: Please make sure that Ghostscript is installed #282

Open
rafiepstein opened this issue Feb 25, 2019 · 88 comments
Open

RuntimeError: Please make sure that Ghostscript is installed #282

rafiepstein opened this issue Feb 25, 2019 · 88 comments
Labels

Comments

@rafiepstein
Copy link

Hello,
Trying to run a single line: (Python 2.7.15 under Pycharm)

import camelot
tables = camelot.read_pdf(inpFile)

Full Stack:
C:\Python27\python.exe "C:\Program Files\JetBrains\PyCharm 2018.2.2\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 51131 --file C:/Users/Rafi/Documents/re_FOCUS/StrataVAR/Python/testPDFTables.py
pydev debugger: process 8344 is connecting

Connected to pydev debugger (build 183.5429.31)
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2018.2.2\helpers\pydev\pydevd.py", line 1741, in
main()
File "C:\Program Files\JetBrains\PyCharm 2018.2.2\helpers\pydev\pydevd.py", line 1735, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files\JetBrains\PyCharm 2018.2.2\helpers\pydev\pydevd.py", line 1135, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:/Users/Rafi/Documents/re_FOCUS/StrataVAR/Python/testPDFTables.py", line 24, in
tables = camelot.read_pdf(inpFile)
File "C:\Python27\lib\site-packages\camelot\io.py", line 106, in read_pdf
layout_kwargs=layout_kwargs, **kwargs)
File "C:\Python27\lib\site-packages\camelot\handlers.py", line 162, in parse
layout_kwargs=layout_kwargs)
File "C:\Python27\lib\site-packages\camelot\parsers\lattice.py", line 351, in extract_tables
self._generate_image()
File "C:\Python27\lib\site-packages\camelot\parsers\lattice.py", line 186, in generate_image
from ..ext.ghostscript import Ghostscript
File "C:\Python27\lib\site-packages\camelot\ext\ghostscript_init
.py", line 24, in
from . import _gsprint as gs
File "C:\Python27\lib\site-packages\camelot\ext\ghostscript_gsprint.py", line 229, in
raise RuntimeError('Please make sure that Ghostscript is installed')
RuntimeError: Please make sure that Ghostscript is installed

Process finished with exit code 1

Windows-10-10.0.17763
('Python', '2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:22:17) [MSC v.1500 32 bit (Intel)]')
('NumPy', '1.16.1')
('OpenCV', '4.0.0')
('Camelot', '0.7.2')

Ghostscript 64 installed under Win10 64 bit:

C:\Users\Rafi>gswin64c.exe -version
GPL Ghostscript 9.26 (2018-11-20)
Copyright (C) 2018 Artifex Software, Inc. All rights reserved.

There is a path to C:\Program Files\gs\gs9.26\bin and to C:\Program Files\gs\gs9.26\bin.

Tracking the source of the Python exception, it seems that the code in __win32_finddll(): fails to find the Registry key.

Using Regedit, there is a key:
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\GPL Ghostscript\9.26
with two entries
GS_DLL: C:\Program Files\gs\gs9.26\bin\gsdll64.dll
and
GS_LIB - C:\Program Files\gs\gs9.26\bin;C:\Program Files\gs\gs9.26\lib;C:\Program Files\gs\gs9.26\fonts

The statement QueryInfoKey(k1) returns (in _gsprint.py)
(0, 0, 131955508546095202L), thus range(0,0) is [] and the loop fails, so the function returns None.

Any suggestions?
Thanks,
--Rafi

@vinayak-mehta
Copy link
Contributor

Did you try the solutions mentioned in #184?

@rafiepstein
Copy link
Author

Hello Vinayak,
I am not sure what you mean by "solution mentioned"...
As far as I could tell, no solution relevant to Windows environment is mentioned.
Ghoscript is installed as per the test suggested. PATH is setup correctly.
The problem seems to be in _gsprint.py,
line: for num in range(0, QueryInfoKey(k1)[0]):
as QueryInfoKey(k1)
(0, 0, 131955739057984515L)
thus range(0, QueryInfoKey(k1)[0]) is empty, and it doesn not find the dll.

Any suggestions?

@tal-yifat
Copy link

I'm having a similar issue, and couldn't solve it using the solutions mentioned in #184. I'd appreciate any suggestions.

Environment
Darwin-17.7.0-x86_64-i386-64bit
Python 3.6.7 | packaged by conda-forge | (default, Feb 28 2019, 02:16:08)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]
NumPy 1.16.2
OpenCV 3.4.4
Camelot 0.7.1
Ghostscript 9.22

I'm using the foo.pdf from the documentation.

tables = camelot.read_pdf('foo.pdf')

And getting the error message:


OSError Traceback (most recent call last)
~/anaconda3/envs/camelot/lib/python3.6/site-packages/camelot/ext/ghostscript/_gsprint.py in
232 try:
--> 233 libgs = cdll.LoadLibrary('libgs.so')
234 except OSError:

~/anaconda3/envs/camelot/lib/python3.6/ctypes/init.py in LoadLibrary(self, name)
425 def LoadLibrary(self, name):
--> 426 return self._dlltype(name)
427

~/anaconda3/envs/camelot/lib/python3.6/ctypes/init.py in init(self, name, mode, handle, use_errno, use_last_error)
347 if handle is None:
--> 348 self._handle = _dlopen(self._name, mode)
349 else:

OSError: dlopen(libgs.so, 6): image not found

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last)
in
----> 1 tables = camelot.read_pdf('foo.pdf')

~/anaconda3/envs/camelot/lib/python3.6/site-packages/camelot/io.py in read_pdf(filepath, pages, password, flavor, suppress_stdout, layout_kwargs, **kwargs)
104 kwargs = remove_extra(kwargs, flavor=flavor)
105 tables = p.parse(flavor=flavor, suppress_stdout=suppress_stdout,
--> 106 layout_kwargs=layout_kwargs, **kwargs)
107 return tables

~/anaconda3/envs/camelot/lib/python3.6/site-packages/camelot/handlers.py in parse(self, flavor, suppress_stdout, layout_kwargs, **kwargs)
159 for p in pages:
160 t = parser.extract_tables(p, suppress_stdout=suppress_stdout,
--> 161 layout_kwargs=layout_kwargs)
162 tables.extend(t)
163 return TableList(tables)

~/anaconda3/envs/camelot/lib/python3.6/site-packages/camelot/parsers/lattice.py in extract_tables(self, filename, suppress_stdout, layout_kwargs)
349 return []
350
--> 351 self._generate_image()
352 self._generate_table_bbox()
353

~/anaconda3/envs/camelot/lib/python3.6/site-packages/camelot/parsers/lattice.py in _generate_image(self)
184
185 def _generate_image(self):
--> 186 from ..ext.ghostscript import Ghostscript
187
188 self.imagename = ''.join([self.rootname, '.png'])

~/anaconda3/envs/camelot/lib/python3.6/site-packages/camelot/ext/ghostscript/init.py in
22 #
23
---> 24 from . import _gsprint as gs
25
26

~/anaconda3/envs/camelot/lib/python3.6/site-packages/camelot/ext/ghostscript/_gsprint.py in
238 libgs = ctypes.util.find_library('gs')
239 if not libgs:
--> 240 raise RuntimeError('Please make sure that Ghostscript is installed')
241 libgs = cdll.LoadLibrary(libgs)
242

RuntimeError: Please make sure that Ghostscript is installed

@QCTW
Copy link

QCTW commented Mar 12, 2019

I have the same issue with the standalone version of Ghostscript (install version is not allowed due to the IT policy in my company). I had set the bin and lib directories of the Ghostscript (standalone) in PATH but Camelot is still trying to find the Ghostscript from the Windows registry.

@pantuts
Copy link

pantuts commented Mar 17, 2019

In macos brew install ghostscript

@tal-yifat
Copy link

In my case, Ghostscript is successfully installed. Shouldn't this be a bug?

@KAIXIE
Copy link

KAIXIE commented Mar 25, 2019

Ghostscript is successfully installed. Shouldn't this be a bug? yes it is a bug!!!!!

@vinayak-mehta
Copy link
Contributor

I'll look into this over the weekend.

@wangxiangtao
Copy link

exact same issue as well. I have the same issue with the standalone version of Ghostscript (install version is not allowed due to the IT policy in my company). I had set the bin and lib directories of the Ghostscript (standalone) in PATH but Camelot is still trying to find the Ghostscript from the Windows registry.

@vinayak-mehta
Copy link
Contributor

vinayak-mehta commented Apr 20, 2019

I currently don't have a Windows machine to reproduce this, let me install it on my current laptop. I believe we should just try to get rid of ghostscript with #96.

@GuillaumeDesforges
Copy link

Same issue here

@marcoloew333
Copy link

Same for me. Even if i install ghostscript and python3-ghostscript via pip.
macOS with PyCharm. Both latest versions.

@ghost
Copy link

ghost commented May 7, 2019

Had the same Issue on Windows. I just installed Ghostscript installer from this Website: https://www.ghostscript.com/download/gsdnld.html My Code is now having no issues.

@ghost
Copy link

ghost commented May 30, 2019

Had the same Issue on Windows. I just installed Ghostscript installer from this Website: https://www.ghostscript.com/download/gsdnld.html My Code is now having no issues.

My code is now having no issues, too, thank you

@cwhan-yonsei
Copy link

I have the same issue. Although I've tried other install method to install ghost script, it still does not work...


OSError Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/camelot/ext/ghostscript/_gsprint.py in
232 try:
--> 233 libgs = cdll.LoadLibrary('libgs.so')
234 except OSError:

~/anaconda3/lib/python3.7/ctypes/init.py in LoadLibrary(self, name)
433 def LoadLibrary(self, name):
--> 434 return self._dlltype(name)
435

~/anaconda3/lib/python3.7/ctypes/init.py in init(self, name, mode, handle, use_errno, use_last_error)
355 if handle is None:
--> 356 self._handle = _dlopen(self._name, mode)
357 else:

OSError: dlopen(libgs.so, 6): image not found

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last)
in
----> 1 endmill_table_list_YG1 = camelot.read_pdf('ALU_endmill.pdf')
2 for table in endmill_table_list_YG1:
3 print(table.parsing_report)

~/anaconda3/lib/python3.7/site-packages/camelot/io.py in read_pdf(filepath, pages, password, flavor, suppress_stdout, layout_kwargs, **kwargs)
104 kwargs = remove_extra(kwargs, flavor=flavor)
105 tables = p.parse(flavor=flavor, suppress_stdout=suppress_stdout,
--> 106 layout_kwargs=layout_kwargs, **kwargs)
107 return tables

~/anaconda3/lib/python3.7/site-packages/camelot/handlers.py in parse(self, flavor, suppress_stdout, layout_kwargs, **kwargs)
160 for p in pages:
161 t = parser.extract_tables(p, suppress_stdout=suppress_stdout,
--> 162 layout_kwargs=layout_kwargs)
163 tables.extend(t)
164 return TableList(tables)

~/anaconda3/lib/python3.7/site-packages/camelot/parsers/lattice.py in extract_tables(self, filename, suppress_stdout, layout_kwargs)
349 return []
350
--> 351 self._generate_image()
352 self._generate_table_bbox()
353

~/anaconda3/lib/python3.7/site-packages/camelot/parsers/lattice.py in _generate_image(self)
184
185 def _generate_image(self):
--> 186 from ..ext.ghostscript import Ghostscript
187
188 self.imagename = ''.join([self.rootname, '.png'])

~/anaconda3/lib/python3.7/site-packages/camelot/ext/ghostscript/init.py in
22 #
23
---> 24 from . import _gsprint as gs
25
26

~/anaconda3/lib/python3.7/site-packages/camelot/ext/ghostscript/_gsprint.py in
238 libgs = ctypes.util.find_library('gs')
239 if not libgs:
--> 240 raise RuntimeError('Please make sure that Ghostscript is installed')
241 libgs = cdll.LoadLibrary(libgs)
242

RuntimeError: Please make sure that Ghostscript is installed

@jtlz2
Copy link

jtlz2 commented Jun 20, 2019

macOS - brew install ghostscript - still get this error

@lswh
Copy link

lswh commented Jun 20, 2019

Hi this error also exists for me.

@lswh
Copy link

lswh commented Jun 20, 2019

I was investigating this code earlier and I noticed for my macOS implementation that it's having some issue with the conditional of libgs.so file which produces the runtime error. I tried working on both virtualenv and conda but I also suspect that the find_library cdll is not working in it somewhere. It does not detect the GhostScript even when I installed from source and did a make so compiled install because that file extension for MacOS is a different one from shared object on Linux. I presume this bug does not happen on Ubuntu/Linux and can only be observed in Windows and MacOS. I will try on a Linux machine and see if I am able to detect the same bug.

@nachiket8188
Copy link

Had the same Issue on Windows. I just installed Ghostscript installer from this Website: https://www.ghostscript.com/download/gsdnld.html My Code is now having no issues.

My code is now having no issues, too, thank you

This did the trick for me too.

@kavinsingh1
Copy link

Had the same Issue on Windows. I just installed Ghostscript installer from this Website: https://www.ghostscript.com/download/gsdnld.html My Code is now having no issues.

I also tried, its working perfectly fine..just after installation

@shivaniarbat
Copy link

Had the same Issue on Windows. I just installed Ghostscript installer from this Website: https://www.ghostscript.com/download/gsdnld.html My Code is now having no issues.

This worked for me too.

@forum2k9
Copy link

Yes, on windows 10 it works after installing the ghostscript exe at: https://www.ghostscript.com/download/gsdnld.html

@sourabhsinha396
Copy link

I had had this issue on aws elasticbeanstalk in a django app while reading a pdf :
I just needed to add these lines
packages:
yum:
ghostscript: []
in the django.configure file

@iicedream
Copy link

Had the same Issue on Windows. I just installed Ghostscript installer from this Website: https://www.ghostscript.com/download/gsdnld.html My Code is now having no issues.
I solved this problom by this url https://www.ghostscript.com/download/gsdnld.html

@slamer59
Copy link

Some hack:

Looking at sources:

k1 = OpenKey(HKEY_LOCAL_MACHINE, "Software\\%s" % key_name)

My guess is that downloading : https://www.ghostscript.com/download/gsdnld.html
install some HKEY_LOCAL_MACHINE aka GS_DLL which solved the problem.

For ones who cannot add HKEY_LOCAL_MACHINE, add it to HKEY_CURRENT_USER\Software\key_name\GS_DLL\GS_DLL
GS_DLL is a REG_SZ containing dll path.

Choose key_name in "AFPL Ghostscript", "Aladdin Ghostscript", "GNU Ghostscript", "GPL Ghostscript",

Also import HKEY_CURRENT_USER here

from _winreg import (

and here:

from winreg import (

@tsiq-maxime
Copy link

tsiq-maxime commented Nov 12, 2019

MacOS, had the same error after running brew install ghostscript

Running brew link --overwrite ghostscript solved it.

@goutam-ghosh
Copy link

goutam-ghosh commented Nov 15, 2019

"errorMessage": "Please make sure that Ghostscript is installed",
"errorType": "RuntimeError"

getting this error while run the code using lambda function aws. Already camelot and ghostscript added as a dependency. I need to resolve as soon as possible. Please help.

my code is :
import camelot

def pdfToJson(event=None,context=None):
tables = camelot.read_pdf("./week-1-2019-20.pdf")
tables[0].df.to_json("./sample.json")

Note:Locally it is working properly.

#serverless #awslambda #python #camelot #ghostscript

@goutam-ghosh
Copy link

And more thing how to add ghostscript dependencies for lambda function python?

@pavankumarg1729
Copy link

Had the same Issue on Windows. I just installed Ghostscript installer from this Website: https://www.ghostscript.com/download/gsdnld.html My Code is now having no issues.

This resolved my issue too

@Cazforshort
Copy link

Same issue. Is there a way I can fix this with out modifying the code? The solutions above don't work if you are dependent on a requirements.in file for containerizing.

@thuynguyetquynh
Copy link

Same issue. I tried: "brew install ghostscript" and it said that my ghostscript was installed but not linked, so I fixed with:

sudo chown -R whoami /usr/local/share/doc/ghostscript/9.54.0
brew link --overwrite ghostscript

Worked perfectly with my MacOs

@kailichou
Copy link

I would recommend to install GhostScript via Chocolatey for Windows OS.

  • Python: 3.8.9
  • OS: Windows 10 Professional

I had this same problem. If you happen to have choco installed in your system.
choco install GhostScript -y

@vinayak-mehta
Copy link
Contributor

vinayak-mehta commented Jul 11, 2021

Can you try installing the latest version with pip install "camelot-py[base]==0.10.1" and then trying out the poppler image conversion backend? Here's a snippet:

import camelot
tables = camelot.read_pdf("https://camelot-py.readthedocs.io/en/master/_static/pdf/foo.pdf", backend="poppler")
tables[0]
# <Table shape=(7, 7)>

More info in the docs here: https://camelot-py.readthedocs.io/en/master/user/advanced.html#use-alternate-image-conversion-backends

Please report issues here: https://github.com/camelot-dev/camelot/issues

@vinayak-mehta
Copy link
Contributor

@rafiepstein Please close this issue If your problem is solved.

@garry8888
Copy link

If it is Windows 10 OS, add direction to the Ghostscript into the environment-variables system-paths (PATH):
C:\Program Files\gs\gs9.54.0\bin
After that restart your PC and try to run your code.
It have solved the proplem in my case.

@lenomosh
Copy link

lenomosh commented Sep 8, 2021

I also had the same issue in Ubuntu. I had to run apt remove ghostscript && apt autoremove -y && apt install ghostscript && reboot

@siddhpant
Copy link

siddhpant commented Jan 20, 2022

I also had the same issue in Ubuntu. I had to run apt remove ghostscript && apt autoremove -y && apt install ghostscript && reboot

Yes, but it is just reinstalling and a useless reboot. Problem lies somewhere else.


When I copy gs and all the related binaries (I cache them in a workflow) to the appropriate paths, read_pdf fails. But when I install with apt, it works. Maybe this might provide a clue?

@simonhuwiler
Copy link

Any updates on this? I have the same problem on my Mac M1 Big Sur.

Tried:

  • install it with brew
  • brew link --overwrite ghostscript (successfull)
  • Installed it from pkg
  • Add the path to every environment path I know
    Nothing works.

This finds the library 👇

import distutils.spawn
distutils.spawn.find_executable("gs")

This not 👇

from ctypes.util import find_library
find_library("gs")

The link /usr/local/bin/ exists and points to the right file.
gs in the terminal works fine as well.

@simonhuwiler
Copy link

simonhuwiler commented Jan 27, 2022

//Edit//

It finally runs. I did this:

Install Ghostscript:

brew install ghostscript

Create System links (change version and path based on your system)

sudo ln -s /opt/homebrew/Cellar/ghostscript/9.55.0/lib/libgs.dylib.9.55 /usr/local/lib/libgs.9.dylib
sudo ln -s /opt/homebrew/Cellar/ghostscript/9.55.0/lib/libgs.dylib.9.55 /usr/local/lib/libgs.dylib
sudo ln -s /opt/homebrew/Cellar/ghostscript/9.55.0/lib/libgs.dylib.9.55 /usr/local/lib/libgs.dylib.9.55

Then checkout camelot version from github:

git clone [email protected]:camelot-dev/camelot.git

Open github folder in terminal and switch branch:

git checkout v0.7.3

Replace ctypes with distutils based on this pull-requests:

  • open file camelot/ext/ghostscript/_gsprint.py
  • add import distutils.spawn where other packages are imported
  • replace libgs = ctypes.util.find_library("gs") with libgs = distutils.spawn.find_executable("gs")

Then create your virtual environment or install it globally:

  • Navigate in your terminal to the camelot folder
  • pip install -r requirements.txt
  • python setup.py install

When everything run smoothly, try to use camelot. For me, I got an error like /usr/local/lib/libgs.dylib: mach-o, but wrong architecture. Then I had do make sure i installed a 64bit python version, create a virtual env based on this version and do all the things above again.

@siddhpant
Copy link

Instead of all that, you could install v0.10.x on <= Python 3.9.x, which removes dependency on ghostscript by adding a poppler backend (which in turn doesn't depend on system packages but rather on another Python library, I guess).

@michaeljcollinsuk
Copy link

In case this helps anyone, I was encountering this on Mac M1 running mac OS Big Sur. I had installed ghostscript with brew install ghostscript and installed camelot with pip. The Ghostscript check specified in the installation docs was failing.

I was able to resolve by adding export DYLD_LIBRARY_PATH="/opt/homebrew/lib" to my .zshrc, after which the above ghostscript check succeeded, and I was able to use camelot.read_pdf("foo.pdf") successfully

@saveyak
Copy link

saveyak commented Mar 2, 2022

This is how I solved for this problem on a Windows computer:

Went to File Explorer -> C drive -> Program Files -> gs -> gs9.55.0 -> shift-clicked on bin folder -> copied as path ("C:\Program Files\gs\gs9.55.0\bin")
Then went to environmental variables -> Path -> Edit -> New -> pasted above -> restarted computer
I ran the following code in Python:

import ctypes
from ctypes.util import find_library
find_library("".join(("gsdll", str(ctypes.sizeof(ctypes.c_voidp) * 8), ".dll")))

The output was "C:\Program Files\gs\gs9.55.0\bin\gsdll64.dll" which means the solution worked. I was then able to install and use Camelot with no problems.

And I heard that this solution works on a Mac: https://jsoma.github.io/m1-install-fixes/python/ghostscript/

@CharlesWit
Copy link

CharlesWit commented Mar 9, 2022

On a M1 Mac with macOS Monterey, after brew install ghostscript, creating the right system links passed the find_library('gs') check :

from ctypes.util import find_library 
find_library('gs')
# '/usr/local/lib/libgs.dylib'

and camelot.read_pdf() worked.
It's part of the solution given above, and it's listed at the link shown in the last comment.

@simonhuwiler Create System links (change version and path based on your system)

sudo ln -s /opt/homebrew/Cellar/ghostscript/9.55.0/lib/libgs.dylib.9.55 /usr/local/lib/libgs.9.dylib
sudo ln -s /opt/homebrew/Cellar/ghostscript/9.55.0/lib/libgs.dylib.9.55 /usr/local/lib/libgs.dylib
sudo ln -s /opt/homebrew/Cellar/ghostscript/9.55.0/lib/libgs.dylib.9.55 /usr/local/lib/libgs.dylib.9.55

@saveyak And I heard that this solution works on a Mac: https://jsoma.github.io/m1-install-fixes/python/ghostscript/

@sowec
Copy link

sowec commented Mar 24, 2022

fwiw, the following worked for me while using pipenv on MacOS.

Install dependencies from the command-line:

brew install python-tk ghostscript tcl-tk

Add packages to PipFile, including, e.g., matplotlib "extra":

[packages]
camelot-py = {version="*", extras=["base", "plot"]}
opencv-python = "*" # for camelot-py
ghostscript = "*" # for camelot-py

Use pipenv shell to run camelot CLI:

pipenv shell
(dir) camelot -f json -o out.json lattice in.pdf

Perhaps due to pipenv, it was not enough to install ghostscript, et al in the system. I needed the python packages for opencv-python and ghostscript. The best way to manage system library dependencies with pipenv is unclear.

Good luck -

@starscream2290
Copy link

you may use this link to properly install ghostscript on win10.. works fine with me now.

https://blog.finxter.com/the-ultimate-guide-to-installing-ghostscript/

@0xspeedrunner
Copy link

Perhaps due to pipenv, it was not enough to install ghostscript, et al in the system. I needed the python packages for opencv-python and ghostscript. The best way to manage system library dependencies with pipenv is unclear.

This worked for me. I had to pip install ghostscript in my conda env

@jsoma
Copy link

jsoma commented Dec 6, 2022

And I heard that this solution works on a Mac: https://jsoma.github.io/m1-install-fixes/python/ghostscript/

Hey, that's mine! And I have a new improved suggestion to solve this for OS X! Three little baby lines of code to solve all your problems:

brew install ghostscript # You probably did this already

mkdir -p ~/lib
ln -s "$(brew --prefix gs)/lib/libgs.dylib" ~/lib

I put together a long writeup about why it works, but the basics:

  • Problem: Newer versions of OS X ship with SIP (System Integrity Protection) which blocks most attempts to use DYLD_* to set library paths. You can disable it, but eh.

  • Solution: It turns out that Python looks in your /Users/username/lib folder for libraries before anywhere else, so all we need to do is drop a symlink in ~/lib to the homebrew ghostscript and we're good to go!

@kevinkjoseph
Copy link

pip install ghostscript should work for Mac users!

@theharshgupta
Copy link

And I heard that this solution works on a Mac: https://jsoma.github.io/m1-install-fixes/python/ghostscript/

Hey, that's mine! And I have a new improved suggestion to solve this for OS X! Three little baby lines of code to solve all your problems:

brew install ghostscript # You probably did this already

mkdir -p ~/lib
ln -s "$(brew --prefix gs)/lib/libgs.dylib" ~/lib

I put together a long writeup about why it works, but the basics:

  • Problem: Newer versions of OS X ship with SIP (System Integrity Protection) which blocks most attempts to use DYLD_* to set library paths. You can disable it, but eh.
  • Solution: It turns out that Python looks in your /Users/username/lib folder for libraries before anywhere else, so all we need to do is drop a symlink in ~/lib to the homebrew ghostscript and we're good to go!

This worked for me, currently on Apple M1

@lmcc-lab
Copy link

Had the same Issue on Windows. I just installed Ghostscript installer from this Website: https://www.ghostscript.com/download/gsdnld.html My Code is now having no issues.

Perfect, works for me

@peter0083
Copy link

pip install ghostscript should work for Mac users!

This works for me!

OS: MacOS Monterey 12.6.1
env: Conda
python 3.11.3

conda create -n myenv python=3.11
conda activate myenv
brew install ghostscript tcl-tk
pip install ghostscript
conda install -c conda-forge camelot-py

@mahdyshabeeb
Copy link

I had the same problem. When running camelot.read_pdf I faced the aforementioned error. And running ctypes.util.find_library("gs") returned no results (which means the gs library could not be found by Python).

I am using MacOS. Following solutions didn't work for me:

  • Adding the directory of libgs.dylib to the PATH environment variable
  • Installing ghostscript with brew or with pip
  • homebrew link --overwrite ghostscript

I haven't tried to install it with conda since I'm not using conda anyway.

I had to follow the steps below to solve the issue:

    ./configure
    make
   make install (might need root privileges) 
  • Then the file libgs.dylib should be found under /opt/homebrew/lib/libgs.dylib (otherwise find this file's path)
  • You need to link this file to /usr/local/lib using the following command (if the directory /usr/local/lib does not exist then create it):
    ln -s /opt/homebrew/lib/libgs.dylib /usr/local/lib/libgs.dylib

After following these steps I could successfully use camelot.

@95anantsingh
Copy link

On M2 Mac this worked -

  1. brew install ghostscript tcl-tk
  2. pip install camelot-py[base]
  3. pip install 'PyPDF2<3.0'

@AbhayTrivedi
Copy link

For Co-Lab
! apt install python3-tk ghostscript

@bosd
Copy link

bosd commented Aug 8, 2024

Hey all!

We try to build a maintained fork at pypdf_table_extraction.

You are welcome to check it out and contribute there.

@paulkg4u
Copy link

On m1 mac the following worked for me

sudo mkdir -p /usr/local/lib
sudo ln -s /opt/homebrew/Cellar/ghostscript/10.04.0/lib/libgs.10.dylib /usr/local/lib/libgs.10.dylib
sudo ln -s /opt/homebrew/Cellar/ghostscript/10.04.0/lib/libgs.dylib /usr/local/lib/libgs.dylib
sudo ln -s /opt/homebrew/Cellar/ghostscript/10.04.0/lib/libgs.dylib.10.04 /usr/local/lib/libgs.dylib.10.04

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests