When trying to run hello-world example
import sys
import ghostscript
args = [
"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 ghostscript
File "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
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 ghostscriptconda install ghostscript, which installs the arm_64 based library from conda-forgeconda install -c conda-forge ghostscriptpip install ghostscriptNote:
_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 basedOk, if you're on mac M1 and using python 3.9 that trick from the mentioned Github issue won't work probably. I did a few times what @Prajual suggested but didn't work either. This helps.
brew install ghostscript
9.56.1_1ls /opt/homebrew/Cellar/ghostscript/
/usr/local/lib/ -- needs sudo privilege. x.xx.xx would be your version from last command!sudo cp /opt/homebrew/Cellar/ghostscript/x.xx.xx/lib/libgs.dylib /usr/local/lib/
You should now be able to import ghostscript with no problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With