python ghostscript: RuntimeError: Can not find Ghostscript library (libgs)

2024/10/9 17:23:49

When trying to run hello-world example

import sys
import ghostscriptargs = ["ps2pdf", # actual value doesn't matter"-dNOPAUSE", "-dBATCH", "-dSAFER","-sDEVICE=pdfwrite","-sOutputFile=" + sys.argv[1],"-c", ".setpdfwrite","-f",  sys.argv[2]]ghostscript.Ghostscript(*args)

getting error:

 File "/Users/ddd/sss/ddd/eee.py", line 2, in <module>import ghostscriptFile "build/bdist.macosx-10.6-universal/egg/ghostscript/__init__.py", line 33, in <module>File "build/bdist.macosx-10.6-universal/egg/ghostscript/_gsprint.py", line 290, in <module>
RuntimeError: Can not find Ghostscript library (libgs)

what is this libgs library and how can I get it?

btw I'm on mac

Answer

For newer user who are using M1 mac, ghostscript might show a missing libgs file error and the file would be unavailable at usr/local/lib

The issue can be resolved by following these steps, in the same order:

  • brew install ghostscript
  • conda install ghostscript, which installs the arm_64 based library from conda-forge
  • If conda throws a channel error try using conda install -c conda-forge ghostscript
  • pip install ghostscript

Note:

  1. The libgs.dylib file can be found in the home brew installation of ghostscript
  2. Changing the address in _gsprint.py will throw an error as the brew installed version will be arm_64 based and the pip installed version will be OS_X86 based
  3. Python doesn't recognise ghostscript module from conda install unless pip install is run, so that is an essential step
https://en.xdnf.cn/q/69994.html

Related Q&A

what is the default encoding when python Requests post data is string type?

with fhe following codepayload = 工作报告 总体情况:良好 r = requests.post("http://httpbin.org/post", data=payload)what is the default encoding when Requests post data is string type? UTF8…

How to initialize a database connection only once and reuse it in run-time in python?

I am currently working on a huge project, which constantly executes queries. My problem is, that my old code always created a new database connection and cursor, which decreased the speed immensivly. S…

Django - ModelForm: Add a field not belonging to the model

Note: Using django-crispy-forms library for my form. If you have a solution to my problem that involves not using the cripsy_forms library, I accept it all the same. Not trying to be picky just need a …

Row by row processing of a Dask DataFrame

I need to process a large file and to change some values.I would like to do something like that:for index, row in dataFrame.iterrows():foo = doSomeStuffWith(row)lol = doOtherStuffWith(row)dataFrame[col…

Tweepy Why did I receive AttributeError for search [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

Running qsub with anaconda environment

I have a program that usually runs inside a conda environmet in Linux, because I use it to manage my libraries, with this instructions:source activate my_environment python hello_world.pyHow can I run …

Flask Application was not able to create a URL adapter for request [duplicate]

This question already has answers here:Flask.url_for() error: Attempted to generate a URL without the application context being pushed(3 answers)Closed 10 months ago.I have this code which used to work…

Python typing deprecation

The latest typing docs has a lot of deprecation notices like the following: class typing.Deque(deque, MutableSequence[T]) A generic version of collections.deque.New in version 3.5.4.New in version 3.6.…

Cant install tensorflow with pip or anaconda

Does anyone know how to properly install tensorflow on Windows?Im currently using Python 3.7 (also tried with 3.6) and every time I get the same "Could not find a version that satisfies the requi…

send xml file to http using python

how can i send an xml file on my system to an http server using python standard library??