Python-camelot (Error: GhostscriptNotFound while it is installed)
Asked Answered
M

19

12

I am trying to extract tabular data from pdf using camelot and I am getting the following error.

Code:

tables = camelot.read_pdf(file_name)

Error:

GhostscriptNotFound: Please make sure that Ghostscript is installed and available on the PATH environment variable

I have already installed Ghostscript and I have it available on the PATH environment variable.

Please find below version details:

  • Windows-10-10.0.17134-SP0
  • Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)]
  • NumPy 1.14.3
  • openCV 3.4.3
  • Camelot 0.3.2

Please help resolve this issue.

Mixtec answered 15/11, 2018 at 12:3 Comment(1)
You can see here how Camelot is trying to find your GhostScript. github.com/socialcopsdev/camelot/blob/… On Windows, it's looking for "gswin32c" or "gswin64c". Can you confirm that you can run "gswin32c" or "gswin64c" on your command line?Belga
L
13

Adding both the "bin" and "lib" paths for Ghostscript to the PATH worked for me:

  • C:\Program Files\gs\gs9.26\bin
  • C:\Program Files\gs\gs9.26\lib

Then you will need to apply that change, depending on the specific use case.

In order of severity

  • Restart Python - this should just work
  • Have Python obtain Gostscript automatically and update the running environment
  • Reboot if you can and as a last resort

Generally and without going into each OS and each environment running the Python interpreter (e.g. Jupyter session, IDE or CLI), a reboot is normally excessive. For some a reboot is not even possible.

Just close and re-open your environment (defined above) after the app installer completes or you have altered the PATH yourself.

There is nothing stopping you from altering the PATH within your Python script using the subprocess module to install the additional application or the os module, or by referencing the apps absolute path e.g.

# Updating the current PATH inside Python

import os
from pathlib import Path
def update_app_path(app, new_path):
    # Get the PATH environment variable
    existing = [Path(p) for p in os.environ["PATH"].split(os.path.pathsep))
    # Copy it, deleting any paths that refer to the application of interest
    new_path = [e for e in existing if not Path(e/app).exists()]
    # Append a the new entry
    new_path.append(new_path)
    # or you could use new_path.append(Path(new_path).parent)
    # Reconstruct and apply the PATH
    os.environ["PATH"] = os.path.pathsep.join(map(str, new_path))

This works as Python takes a copy of the current environment when it starts and anything it then does after that, using os or shell calls, uses that copied environment. Altering the environment within Python does not change the user's environemnt outside of that running Python, and changes in this way are not permanent unless deliberately made so.

Lindie answered 28/12, 2018 at 22:32 Comment(2)
Worked for me (win 10). Note: The ghostscript installer only adds the bin path to the PATHFrankforter
Worked for me, but I had to Reboot for it to workSingultus
S
5

I uninstalled the 64bit and

  1. Install the 32bit version

  2. Add the following two paths to the PATH Windows environment:

    C:\Program Files(x86)\gs\gs9.26\bin

    C:\Program Files(x86)\gs\gs9.26\lib

and now it works

Substantive answered 2/6, 2020 at 20:53 Comment(2)
just to clarify by saying add the path is for windows to add it on the ENVIRONMENT VARIABLES PATH? ThanksImpi
Yep exactly, i modify the answer.Substantive
P
3

Download Ghostscript from here https://www.ghostscript.com/download/gsdnld.html and add it to the path if required

Poulson answered 6/12, 2018 at 10:42 Comment(1)
Hello! you mean like environment variables path? I'm on windows by the way.Impi
A
2

For me using brew link -f --overwrite ghostscript solved the issue. I would recommend checking the suggested solutions on https://github.com/atlanhq/camelot/issues/282. That's where I also found my fix.

Appointive answered 20/11, 2019 at 22:53 Comment(0)
A
1

Tried all the solutions. The only option that works is to use 32 bit ghostscript.

Arezzo answered 27/8, 2020 at 22:13 Comment(2)
Welcome to Stack Overflow. Your late answer here duplicates two existing answers from M Mehmood and Alessandra without adding anything new or different. Duplication is rarely good, and it may result in down-votes as others see it as an unwanted distraction (possibly also leading up to removal by moderators, see How to handle cleanup of late blatantly duplicate answers ('surfing') on popular questions for reference).Tymbal
As you're starting out here, please take the tour to learn how Stack Overflow works and refer to How do I write a good answer?.Tymbal
E
1

I solved this problem.

  1. I downloaded Ghostscript.
  2. Then installed it at C:/programfiles.
  3. Added set path: C:\Program Files\gs\gs9.26\bin + C:\Program Files\gs\gs9.26\lib
  4. Restarted my computer.

After these steps, it worked.

Engender answered 26/11, 2021 at 8:12 Comment(1)
P
1

For me, uninstalling camelot and re-installing with conda install -c conda-forge camelot-py instead of pip solved the problem (as ghostscript is also re-installed)

Pistole answered 5/1, 2022 at 13:50 Comment(0)
C
1

In case you are fed up with all the errors derived from the usage of Ghostscript and want to find a way to use Camelot without using Ghostscript, here is the fork of it which does not rely on it. Camelot fork without Ghostscript

Installation guide is similar, but this time from the github repo itself.

First, install these dependencies:

!pip install pdf2image
!pip install python-dateutil
!apt-get install poppler-utils 

Then clone the repo

$ git clone https://www.github.com/h2oai/camelot

Finally, go to the repo directory and install camelot from there.

$ cd camelot
$ pip install ".[base]"

Import camelot and happily use it :)

Citronella answered 3/10, 2022 at 15:10 Comment(0)
O
0

I had the same problem. I solved it by uninstalling the 64 bit version and installing the 32 bit version.

Opposition answered 6/8, 2020 at 0:40 Comment(0)
P
0

I realized that. If you are using the Python 64bit you need install ghostcript64 bit, else 32 bit.

Also set path for 64bit: C:\Program Files\gs\gs9.26\bin C:\Program Files\gs\gs9.26\lib

or for below for 32bit C:\Program Files(x86)\gs\gs9.26\bin C:\Program Files(x86)\gs\gs9.26\lib

Pompey answered 31/8, 2021 at 9:7 Comment(1)
Using python 64bits, ghostcript64bit (9.55.0) and the path : C:\Program Files\gs\gs9.55.0\bin and C:\Program Files\gs\gs9.55.0\lib works to me.Troposphere
A
0

Here is my solution (Windows OS (11, 64 BIT)):

  1. Download and install the desired ghost version you wish (32,64 - does not matter)
  2. Using "dir /x" command, get the short version of the path of your installation (c:\progra~1\blahbla...). My location (I love altering the default suggestion) is "C:\Program Files\gs\GPLGhostScript" and the short name is "c:\progra~1\gs\GPLGhostScript"
  3. Add this to the path together with \bin. In my case "c:\progra~1\gs\GPLGhostScript\bin" (no need for lib path as suggested by others)
  4. Restart your PC
  5. Test your installation of GhostScript according to this link.

Good luck :)

Abnormity answered 10/10, 2021 at 5:53 Comment(0)
E
0

A very simple way is to install Ghostscript from the official website.

Then give the location while set-up the library in the Anaconda script folder. Wait for 10 minutes after closing the Python platforms.

Ethiopic answered 11/10, 2021 at 12:55 Comment(0)
E
0

This worked for me:

C:\Program Files\gs\gs9.55.0\bin

Just find the path location, copy it, and paste it into user and system variables Path (Environment variables).

Enate answered 20/10, 2021 at 4:48 Comment(3)
How do I paste its path into user and system variables Path? @AlexanderGarzoCoupe
Search on google/youtube how to set your variables path.Enate
Search for "Environmental Variables" on your computer, click "Path", then "Edit", then "New", paste in the path location, click OK, then restart your computer.Johannajohannah
W
0

I was facing same issue for 2 days. I found solution at below link.

for windows 10, I used below method

  1. in "search the web and windows" write "under edit environment variable for your account in control panel."
  2. edit path for lib and bin library of Ghostscript here. add ; to separate the path at end also. set path in environment variable

For more info used below link. It worked fine for me.

https://github.com/atlanhq/camelot/issues/465#issuecomment-975976344

Wendling answered 16/12, 2021 at 6:25 Comment(0)
P
0

For those who might be stuck with ghostscript, as per the official documentation, ghostscript will be replaced by poppler as the default image conversion backend in v0.12.0.

For now, you can avoid the whole ghostscript issue by changing the image conversion backend in the reader:

import camelot 
camelot.read_pdf("example.pdf",backend="poppler")
Pomade answered 21/5, 2023 at 11:18 Comment(0)
U
0

I faced the same error when running camelot.read_pdf() and ctypes.util.find_library("gs") returned no results (which means the gs library could not be found by Python). I am using a MacOS. I tried following solutions which didn't help:

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

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

I could finally resolve the issue by going through the following steps:

./configure
make
make install (might need root privileges)
  • Then the file libgs.dylib should be found under /opt/homebrew/lib/libgs.dylib

  • You need to link this file to /usr/local/lib using the following command (if the directory /usr/local/lib doesn't exist then you need to create it)

ln -s /opt/homebrew/lib/libgs.dylib /usr/local/lib/libgs.dylib
Unlive answered 3/10, 2023 at 20:39 Comment(0)
S
0

I have added below two lines and it is working for me:

# Path to the directory containing gsdll64.dll
# Path where i have gs(ghost script) installed
dll_dir = 'C:/Program Files/gs/gs10.02.1/bin'

# Add the directory to the PATH variable
os.environ['PATH'] += ';' + dll_dir

# Above two lines added before using camelot
def extract_tables_camelot(pdf_file):
    tables = camelot.read_pdf(pdf_file, pages="all")
    return tables
Shanney answered 29/2 at 15:35 Comment(0)
J
-1

This is how I solved for this error on a Windows computer, similar to what Alexander Garzo posted:

  1. 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")
  2. Then went to environmental variables -> Path -> Edit -> New -> pasted above -> OK -> restarted computer.

I then 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.

Johannajohannah answered 2/3, 2022 at 21:59 Comment(0)
T
-2

I was getting this Error (OSError: Ghostscript is not installed. You can install it using the instructions here: https://camelot-py.readthedocs.io/en/master/user/install-deps.html) I tried everything mentioned here and also in Github. but after installing Ghostscript from here and then adding to the PATH. I keep trying methods to solve it. BUT the solution is to just Restart your computer and everything Works. so Restart is Must.

Tensor answered 11/8, 2021 at 10:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.