ruby 找不到phantomjs

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30703886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 06:44:36  来源:igfitidea点击:

Could not find phantomjs

rubyubuntuphantomjs

提问by Sergey Evstifeev

Getting the following error when trying to use phantomjs from ruby on Ubuntu:

尝试在 Ubuntu 上使用来自 ruby​​ 的 phantomjs 时出现以下错误:

 Failure/Error: visit root_path
 Cliver::Dependency::NotFound:
   Could not find an executable ["phantomjs"] on your path.
 # ./spec/features/search_spec.rb:17:in `block (2 levels) in <top (required)>'
 # ./spec/support/vcr.rb:23:in `block (3 levels) in <top (required)>'
 # ./spec/support/vcr.rb:23:in `block (2 levels) in <top (required)>'

phantomjs was built locally and added to PATH. How do I make ruby find phantomjs?

phantomjs 在本地构建并添加到 PATH。如何让 ruby​​ 找到 phantomjs?

回答by Matthew

You can also do

你也可以这样做

$ sudo apt-get install phantomjs                               

That should automatically add phantomjs to your path, and do everything else necessary for it to run correctly. This worked for me.

这应该会自动将 phantomjs 添加到您的路径中,并执行其他一切使其正确运行所需的操作。这对我有用。

回答by pjammer

Instead of building locally, use homebrew on your mac with brew install phantomjsand all the paths will link after. I had this error myself, and you'll get the links for free and have the ability to update easily.

不要在本地构建,而是在您的 mac 上使用自制软件,brew install phantomjs然后所有路径都将链接。我自己也遇到过这个错误,您将免费获得链接并能够轻松更新。

回答by Aamir

For Mac Os El Capitanuse following command:

对于Mac Os El Capitan使用下面的命令:

npm install -g phantomjs

Above command only works if you have installed npm, for installing npm:

以上命令仅在您安装后才有效npm,用于安装npm

 brew install npm

回答by gayavat

add to Gemfile

添加到 Gemfile

gem 'phantomjs', :require => 'phantomjs/poltergeist'

or put code below to spec_helper.rb

或者把下面的代码放到spec_helper.rb

require 'phantomjs' 
Capybara.register_driver :poltergeist do |app|
    Capybara::Poltergeist::Driver.new(app, :phantomjs => Phantomjs.path)
end

https://github.com/colszowka/phantomjs-gem

https://github.com/colszowka/phantomjs-gem

回答by Sergey Evstifeev

Apparently, the solution was to add phantomjs not only to the PATH, but also create links:

显然,解决方案是不仅将 phantomjs 添加到 PATH,还要创建链接:

sudo ln -s /home/myuser/phantomjs/bin/phantomjs /usr/bin/phantomjs
sudo ln -s /home/myuser/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -s /home/myuser/phantomjs/bin/phantomjs /usr/local/share/phantomjs

Adjust the /home/myuser/phantomjs/bin/phantomjspaths to match the path to phantomjs binary on your machine.

调整/home/myuser/phantomjs/bin/phantomjs路径以匹配机器上 phantomjs 二进制文件的路径。

回答by hlcs

Other possible solution is to add executable rights to file:

其他可能的解决方案是向文件添加可执行权限:

# download phantomjs
$ curl --output /home/user/.rvm/bin/phantomjs https://s3.amazonaws.com/circle-downloads/phantomjs-2.1.1
# set rights 
$ chmod +x /home/user/.rvm/bin/phantomjs
# check
$ which phantomjs
/home/user/.rvm/bin/phantomjs

And also it is not recommended by poltergeistto use phantomjsfrom official Ubuntu repos:

而且不建议用骚灵,以使用phantomjs从Ubuntu官方回购:

DO NOT use phantomjs from the official Ubuntu repositories, since it doesn't work well with poltergeist.

不要使用来自官方 Ubuntu 存储库的 phantomjs,因为它不能很好地与 poltergeist 一起使用。