I'm trying to run a ruby script in the mac automator. First of all, I chosen "Run Shell script" and in the drop down for that I choose /bin/zsh instead of /usr/bin/ruby, beacuse I want to run ruby 2.3.0 and not whatever version there was in /usr/bin/ruby.
/Users/me/.rvm/rubies/ruby-2.3.0/bin/ruby /Users/me/Projects/Private/SubSeeker/main.rb $1
This is how the automator script looks like, and it runs well till that point I have to require something. For example when I require rest-client, I do it like this: require 'rest-client' but for some reason that doesn't work. I get this error:
/Users/me/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- rest-client (LoadError)
from /Users/me/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/me/Projects/Private/SubSeeker/scraper.rb:1:in `<top (required)>'
from /Users/me/Projects/Private/SubSeeker/main.rb:4:in `require_relative'
from /Users/me/Projects/Private/SubSeeker/main.rb:4:in `<main>'
The gem is installed and I can use the script when not running through automator.
Any idea what I'm doing wrong here?
Related
I'm using chruby to manage my Ruby versions, and Bundler's binstubs to avoid having to type "bundle exec". I'm running into issues I don't totally understand. Here's what I get when I try to run the test suite in our (Rails 4, Ruby 2.2.2) application:
$ rspec
/Users/duncanmalashock/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- simplecov (LoadError)
from /Users/duncanmalashock/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/duncanmalashock/ruby_projects/platform/spec/spec_helper.rb:3:in `<top (required)>'
from /Users/duncanmalashock/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/duncanmalashock/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/duncanmalashock/ruby_projects/platform/spec/controllers/admin/admin_controller_spec.rb:1:in `<top (required)>'
from /Users/duncanmalashock/.gem/ruby/2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in `load'
from /Users/duncanmalashock/.gem/ruby/2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in `block in load_spec_files'
from /Users/duncanmalashock/.gem/ruby/2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in `each'
from /Users/duncanmalashock/.gem/ruby/2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in `load_spec_files'
from /Users/duncanmalashock/.gem/ruby/2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:102:in `setup'
from /Users/duncanmalashock/.gem/ruby/2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:88:in `run'
from /Users/duncanmalashock/.gem/ruby/2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:73:in `run'
from /Users/duncanmalashock/.gem/ruby/2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:41:in `invoke'
from /Users/duncanmalashock/.gem/ruby/2.2.2/gems/rspec-core-3.3.2/exe/rspec:4:in `<top (required)>'
from /Users/duncanmalashock/.gem/ruby/2.2.2/bin/rspec:23:in `load'
from /Users/duncanmalashock/.gem/ruby/2.2.2/bin/rspec:23:in `<main>'
When I run $ bundle exec rspec, the suite runs correctly. I've been looking into postmodern's gem_home, and have installed it, but it's not giving me the results I'm looking for. I'm using zsh on OSX Yosemite.
in .zshrc:
source /usr/local/share/chruby/chruby.sh
source '/usr/local/share/chruby/auto.sh'
source /usr/local/share/gem_home/gem_home.sh
export PATH=./.bundle/bin:$PATH
alias b='bundle install --path .bundle/gems --binstubs .bundle/bin'
Just install the simplecov gem in your system (simply do: gem install simplecov) and run your test again. It will work.
But, it's a better practice to use bundle exec to run the rake or rspec commands. Because that way, you would ensure that the command is running in the context of your Gemfile.
You can add these aliases to your .zshrc file:
alias ber="bundle exec rspec"
alias be="bundle exec"
And, then run your rspec tests like this:
ber
or,
be rspec
Your problem is that bundler has installed simplecov local to the project and you are trying to run the system global rspec. That is going to look for simplecov in the system ruby library location. Using a Ruby language version manager is not going to change this behaviour. It will just use the versioned ruby's library location instead.
If you wish your versioned Ruby to use rspec and simplecov together then you need to install simplecov in your versioned ruby using whatever tool equivalent to gem that is provided.
I am not sure why you find running bundle exec of great import. One can always create an alias in .bashrc or .bash_profile. I have two for bundle exec, one is be and the other bexec. I also have aliases for bundle exec rails (brails) and bundle exec rake (break). In practice I find that these are really little different than running the customary commands.
I'm learning Ruby from "Beginning Ruby from Novice to Professional" by Peter Cooper. I am on Chapter 7. I have ruby 2.0 installed. I am facing this error:
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- 2.0/redcloth_scan (LoadError)
When trying to run this code:
require 'rubygems'
require 'RedCloth'
r = RedCloth.new("This is a *test* of _using RedCloth_")
puts r.to_html
I'm getting this result:
ruby redcloth.rb
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- 2.0/redcloth_scan (LoadError)
Couldn't load 2.0/redcloth_scan
The $LOAD_PATH was:
C:/Ruby200/lib/ruby/gems/2.0.0/gems/RedCloth-4.2.9-x86-mingw32/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/RedCloth-4.2.9-x86-mingw32/lib/case_sensitive_require
C:/Ruby200/lib/ruby/gems/2.0.0/gems/RedCloth-4.2.9-x86-mingw32/ext
C:/Ruby200/lib/ruby/site_ruby/2.0.0
C:/Ruby200/lib/ruby/site_ruby/2.0.0/i386-msvcrt
C:/Ruby200/lib/ruby/site_ruby
C:/Ruby200/lib/ruby/vendor_ruby/2.0.0
C:/Ruby200/lib/ruby/vendor_ruby/2.0.0/i386-msvcrt
C:/Ruby200/lib/ruby/vendor_ruby
C:/Ruby200/lib/ruby/2.0.0
C:/Ruby200/lib/ruby/2.0.0/i386-mingw32
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/RedCloth-4.2.9-x86-mingw32/lib/RedCloth.rb:13:in `<top (required)>'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
from redcloth.rb:2:in `<main>'
Exit code: 1
I already installed ruby gems and RedCloth. They didn't give me an errors. If somebody could shed some light on this topic it would be greatly appreciated.
try this:
goto into C:/Ruby200/lib/ruby/gems/2.0.0/gems/RedCloth-4.2.9-x86-mingw32/lib
and create a dir named '2.0'.
Then copy redcloth_scan.so from 'C:/Ruby200/lib/ruby/gems/2.0.0/gems/RedCloth-4.2.9-x86-mingw32/lib' into '2.0' dir.
I installed in past RedCloth with Ruby 1.9.1.
Actually I suspect that RedCloth doesn't work with Ruby 2.0.
On ruby 2.x.x you need to compile the gem.
For example for the windows ruby 2.2.4:
Setup the DevKit (https://github.com/oneclick/rubyinstaller/wiki/Development-Kit)
Run into command window:
gem install RedCloth --platform=ruby
Goto to your installed RedCloth path
lib\ruby\gems\2.2.0\gems\RedCloth-4.2.9\lib
Create there a new directory called "2.2" and copy the file redcloth_scan.so on it.
If you use the gem RedCloth-4.2.9-x86-mingw32, the redcloth_scan.so contains the ruby 1.9 dependency and it doesn't works with ruby 2.2.4.
I've tried all of the other solutions people have talked about on here, but none of them have helped / applied.
I've written a Ruby script that requires the spreadsheet gem. The requiring works fine when I execute the script normally with ruby myscript.rb, but after running chmod +x myscript.rb, and then trying to run the program with ./myscript.rb I get the following error....
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- spreadsheet (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Users/fcangialosi/dev/mTC/parse.rb:2:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Users/fcangialosi/dev/mTC/interpreter.rb:1:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from ./pmcnp.rb:7:in `<main>'
The beginning of my script looks like this:
#!/usr/bin/ruby
require 'rubygems'
require 'spreadsheet'
If anyone has any ideas, I would really appreciate it.
From your answers to the comments, the ruby you're running normally - and therefore the one in which your gems are installed - is /Users/fcangialosi/.rbenv/shims/ruby. When you make the script executable, it uses the hint in the script to know which program to use to execute the script. In your case, you have:
#!/usr/bin/ruby
So that's using whichever ruby version you have installed in /usr/bin/ruby. In order to use your rbenv ruby instead of /usr/bin/ruby, change the shebang line to:
#!/usr/bin/env ruby
I'm using Archlinux, the ruby location was on /usr/bin/ruby
$ ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux]
$ gem install ffi
Building native extensions. This could take a while...
Successfully installed ffi-1.9.0
Parsing documentation for ffi-1.9.0
Done installing documentation for ffi after 41 seconds
1 gem installed
I was using G-WAN to execute a ruby script, but when i use require 'ffi' this output shown:
/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- ffi (LoadError)
from /usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/asd/bin/gwan_linux32-bit/127.0.0.1_8081/#127.0.0.1/csp/test.rb:1:in `<main>'
and require '/home/asd/.gem/ruby/2.0.0/gems/ffi-1.9.0/lib/ffi.rb' shows:
/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- ffi_c (LoadError)
from /usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/asd/.gem/ruby/2.0.0/gems/ffi-1.9.0/lib/ffi.rb:14:in `rescue in <top (required)>'
from /home/asd/.gem/ruby/2.0.0/gems/ffi-1.9.0/lib/ffi.rb:3:in `<top (required)>'
from /usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/asd/bin/gwan_linux32-bit/127.0.0.1_8081/#127.0.0.1/csp/test.rb:21:in `<main>'
the output of p $LOAD_PATH was:
["/usr/lib/ruby/site_ruby/2.0.0" # doesn't exists
, "/usr/lib/ruby/site_ruby/2.0.0/i686-linux" # doesn't exists
, "/usr/lib/ruby/site_ruby" # doesn't exists
, "/usr/lib/ruby/vendor_ruby/2.0.0" # doesn't exists
, "/usr/lib/ruby/vendor_ruby/2.0.0/i686-linux" # doesn't exists
, "/usr/lib/ruby/vendor_ruby" # doesn't exists
, "/usr/lib/ruby/2.0.0"
, "/usr/lib/ruby/2.0.0/i686-linux"
]
the location for FFI was:
$ locate ffi.rb
/home/asd/.gem/ruby/2.0.0/gems/ffi-1.9.0/lib/ffi.rb
/home/asd/.gem/ruby/2.0.0/gems/ffi-1.9.0/lib/ffi/ffi.rb
/opt/jruby/lib/ruby/shared/ffi.rb
/opt/jruby/lib/ruby/shared/ffi/ffi.rb
/opt/jruby/samples/ffi/ffi.rb
so i tried to add the directory to $LOAD_PATH
$LOAD_PATH.unshift '/home/asd/.gem/ruby/2.0.0/gems/ffi-1.9.0/lib'
and now require 'ffi' shows no error..
if i already have many gems installed on ~/.gem/ruby/2.0.0/gems
$ ll ~/.gem/ruby/2.0.0/gems/ | wc
285 2558 17502
what is the correct way to use the gem? is it by adding each path to $LOAD_PATH
This is clearly a Ruby configuration issue, and the suggested RVM tool seems to address it:
RVM is a command-line tool which allows you to easily install, manage,
and work with multiple ruby environments from interpreters to sets of
gems.
As suggested by 'icktoofay', G-WAN could add support for RVM, but I am not sure that it makes sense unless RVM becomes more mainstream than Ruby itself (or assimilated by Ruby).
Now, Jesly Varghese also told us (above) that the issue comes from the fact "you are using system ruby, and calling a gem in user dir".
Did you try to install G-WAN under /opt/gwan ?
Then, this PATH issue may be gone.
I am trying to run a ruby script to rename some files but I get the following error:
Eccleshall$ ruby rename.rb
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- ftools (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from rename.rb:45:in `<main>'
Thanks for the help.
Change to script to say:
require "fileutils"
instead of
require "ftools"
ftools has been deprecated.