【问题标题】:Ghostscript installed but not found RGhost::Config::GS[:path]='/path/to/my/gs'Ghostscript 已安装但未找到 RGhost::Config::GS[:path]='/path/to/my/gs'
【发布时间】:2021-01-13 22:23:11
【问题描述】:

我已经尝试了几个小时来解决这个问题,我到处寻找解决方案,但没有找到。我正在尝试为我的项目运行规范测试,但出现以下错误:

RuntimeError:
 
   Ghostscript not found in your system environment (linux-gnu).
   Install it and set the variable RGhost::Config::GS[:path] with the executable.
   Example: RGhost::Config::GS[:path]='/path/to/my/gs' #unix-style
    RGhost::Config::GS[:path]="C:\\gs\\bin\\gswin32c.exe"  #windows-style

我确实尝试输入 RGhost::Config::GS[:path]='/usr/local/bin/gs' 并返回:

bash: RGhost::Config::GS[:path]=/usr/local/bin/gs: No such file or directory

但 ghostscript 已安装,我做了所有事情(make、sudo make install 等),当我运行 gs -v 时它返回:

GPL Ghostscript 9.26 (2018-11-20)
Copyright (C) 2018 Artifex Software, Inc.  All rights reserved.

当我使用用户界面并在“文件”应用程序中搜索“gs”时,在/home/marcelle/projects/ghostscript-9.26/bin/gs 中找到了它,我也尝试了:

RGhost::Config::GS[:path]='/home/marcelle/projects/ghostscript-9.26/bin/gs'

它返回相同的错误:

bash: RGhost::Config::GS[:path]=/home/marcelle/projects/ghostscript-9.26/bin/gs: No such file or directory

我还尝试使用 autoremove 和 purge 从我的笔记本中删除 ghostscript,然后使用我之前提到的(./configure、make、sudo make install)重新安装它,重新启动笔记本、终端,什么都没有。

PS:我使用的是 Ubuntu 20.04。

【问题讨论】:

标签: ruby-on-rails ruby ruby-on-rails-5 runtime-error ghostscript


【解决方案1】:

我设法找到了解决方案。寻找 Rghost 的代码,我在其规范中看到的是预期的路径与 ghostscript 的实际路径不同。 当我在终端上运行 whereis 或 which 时,它会返回:

which gs
/usr/local/bin/gs

所以我试图指出这条路。但是看到我在github for Rghost 上找到的 Rghost 规范测试,我们可以看到它需要 /usr/bin/gs:

 it 'should detect linux env properly' do
    RbConfig::CONFIG.should_receive(:[]).twice.with('host_os').and_return('linux')
    File.should_receive(:exists?).with('/usr/bin/gs').and_return(true)
    RGhost::Config.config_platform
    RGhost::Config::GS[:path].should == '/usr/bin/gs'
  end

所以它需要 /usr/bin 而不是 /usr/local/bin。 然后我只是复制到那个路径并且规范运行没有问题了:

sudo cp /usr/local/bin/gs /usr/bin

【讨论】:

  • 注意:我认为 Linux 中更常见的做法是创建符号链接而不是复制文件:ln -s /usr/local/bin/gs /usr/bin/gs
【解决方案2】:

我完全没有使用 Ruby 的经验,但是我在使用 asciidoctor 时也遇到了这个错误,它使用 rghost 生成 PDF。

错误中提到的命令RGhost::Config::GS[:path]='/path/to/my/gs'不是shell命令,这就是bash无法处理的原因。但是,对我来说,也不清楚如何处理这个命令。我希望有一种简单的方法可以在某处设置此变量,但找不到。

对我有用的是搜索 rghost.rb 文件,这是设置此变量并且可以更改的位置。在 Windows 中,它位于C:\Ruby30-x64\lib\ruby\gems\3.0.0\gems\rghost-0.9.7\lib\rghost.rb

在此文件中,我添加了以下行,从而解决了问题:

RGhost::Config::GS[:path]="C:\\Program Files\\gs\\gs9.55.0\\bin\\gswin64c.exe"

注意:上述路径可能因人而异,因此请确保使用对您的系统有效的路径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-14
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多