【问题标题】:python ghostscript: RuntimeError: Can not find Ghostscript library (libgs)python ghostscript:RuntimeError:找不到Ghostscript库(libgs)
【发布时间】:2011-07-27 17:52:10
【问题描述】:

尝试运行 hello-world 示例时

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)

出现错误:

 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)

这个 libgs 库是什么?如何获得它?

顺便说一句,我在 mac 上

【问题讨论】:

    标签: python macos ghostscript


    【解决方案1】:

    对于使用 M1 mac 的新用户,ghostscript 可能会显示缺少 libgs 文件错误,并且该文件将在 usr/local/lib 不可用

    可以按照以下步骤以相同的顺序解决该问题:

    • brew install ghostscript
    • conda install ghostscript,从 conda-forge 安装基于 arm_64 的库
    • 如果 conda 引发通道错误,请尝试使用 conda install -c conda-forge ghostscript
    • pip install ghostscript

    注意:

    1. libgs.dylib 文件可以在 ghostscript 的 home brew 安装中找到
    2. 更改_gsprint.py 中的地址将引发错误,因为 brew 安装的版本将基于 arm_64 而 pip 安装的版本将基于 OS_X86
    3. 除非运行 pip install,否则 Python 无法识别 conda install 中的 ghostscript 模块,因此这是必不可少的步骤

    【讨论】:

      【解决方案2】:

      对我来说,我只是安装了 python 部分:

      pip install ghostscript
      

      但不是 C 部分:

      brew install ghostscript
      

      也许这些 DMG 也可以使用 - 但我没有走这条路: http://pages.uoregon.edu/koch/

      【讨论】:

        【解决方案3】:

        您应该看看Ghostscript's official download sitetheir documentation

        如果这不能让您开始,您也可以直接在 IRC 服务器 irc.freenode.net 上名为 #ghostscript 的在线聊天频道中询问 GS 开发人员。他们是一群非常友好和乐于助人的人。

        【讨论】:

          【解决方案4】:

          要解决这个问题,你需要修改site-packages中的ghostscript模块路径。

          在 _gsprint.py 中修改成这样:

          libgs = ctypes.util.find_library('/opt/local/lib/libgs')

          它会定位您的 libgs 文件。

          【讨论】:

            【解决方案5】:

            对于 Mac 用户,请在您的 /usr/local/lib/ 目录中找到 libgs.x.xx.dylib 的版本。

            然后运行这个命令,

            ln -s /usr/local/lib/libgs.x.xx.dylib /usr/local/lib/libgs.so
            
            echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/' >> ~/.zshrc
            

            .zshrc 替换为您的 shell 脚本类型。

            [将 x.xx 替换为您目录中的版本]

            【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-12-21
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多