require gem issue - ruby-on-rails-3

I have installed google api client with the following code and it installed successfuly.
gem install google-api-client
I am using rails 3.0.3 so i also included the above line bundler and ran bundle install which went successfully.
I have also rvm installed. And created a gemset.
And when I run the following command in the terminal:
gem environment | grep INSTALLATION | awk '{print $4}'
It gives me the following result
/home/jamal/.rvm/gems/ruby-1.9.3-p194
When i try to execute the following code in scintilla outside the project directory. It gives me an error.
require 'rubygems'
require 'google/api_client'
ERROR:
usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- google/api_client (LoadError)
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
What is the main reason of this kind of error?

Possible chances are your editor does not loading the specific gemset in which you install the gem.
Please provide output of gem list google-api-client -d in your questions. So that I can figure it out exactly what is going one.
EDIT:
Another issue which usually occurs are the dual installation of ruby. When we do have a system level installation and a rvm installation, many editor got confused in it. They load up original system installed ruby which do have prefixes like 1.8.7, 1.9.1and available in /usr/share/bin/. Where was you had installed the gem in rvm profile. To overcome this problem you must run your code from terminal after choosing the right gemset

I had that google/api_client (LoadError) message but, it concerned another Google gem.
gem 'google_drive', '~> 0.3.10'
gem 'google-api-client'
I just removed the , '~> 0.3.10' part in case of it was a compatibility problem. That did the trick:
Using google-api-client 0.7.1 (was 0.9.4)
Installing google_drive 1.0.6 (was 0.3.11)

Related

Ruby cannot find gem in gemset

I apologize if I've missed something obvious. I am new to Ruby.
My overall goal is to add functionality to an existing script, which is using rvm and gemsets.
When I install new gems to a particular gemset, the requires in my scripts fail to find them. I am using the following rvm instance:
$ rvm current
jruby-1.6.7.2#preflight
To confirm:
$ which ruby
/Users/user/.rvm/rubies/jruby-1.6.7.2/bin/ruby
$ ruby -v
jruby 1.6.7.2 (ruby-1.8.7-p357) (2012-05-01 26e08ba) (Java HotSpot(TM) 64-Bit Server VM 1.8.0_11) [darwin-x86_64-java]
I specified the gemset into I install a given gem (let's say xml-simple).
$ rvm #preflight do gem install xml-simple
Successfully installed xml-simple-1.1.5
1 gem installed
To verify the gem installed correctly:
$ gem list
*** LOCAL GEMS ***
...
xml-simple (1.1.5)
...
We see the module I installed there.
Following the xml-simple instructions to include the module, I run this script:
require 'xmlsimple'
which, results in:
$ ruby testver.rb
LoadError: no such file to load -- xmlsimple
require at org/jruby/RubyKernel.java:1033
(root) at testver.rb:1
One suspicious thing I have seen is that printing out RUBY_VERSION and $LOAD_PATH shows me this:
$ ruby testver.rb
1.8.7
/Users/user/.rvm/rubies/jruby-1.6.7.2/lib/ruby/site_ruby/1.8
/Users/user/.rvm/rubies/jruby-1.6.7.2/lib/ruby/site_ruby/shared
/Users/user/.rvm/rubies/jruby-1.6.7.2/lib/ruby/1.8
.
Adding require "rubygems" is required prior to Ruby version 1.9.2, per this stackoverflow answer. This resolved my issue.

Error "...cannot load such file -- mysql2/2.0/mysql2 (LoadError)". On Windows XP with Ruby 2.0.0

The command rails server throws this error.
C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/mysql2.rb:2:in `require': cannot load
such file -- mysql2/2.0/mysql2 (LoadError)
I use Ruby 2.0.0 from RubyInstaller on Windows XP box.
I figured out what is the problem but I don't know how to solve it. The problem is that there is no any 2.0/ directory in the mysql2-0.3.11-x86-mingw32 gem. This is the gem that rails installs as its dependency from Gemfile:
GEM
remote: https://rubygems.org/
specs:
... many gems here
mysql2 (0.3.11-x86-mingw32)
... many gems here
DEPENDENCIES
...
mysql2
...
This is what is in that mysql2.rb file:
# C:\Ruby200\lib\ruby\gems\2.0.0\gems\mysql2-0.3.11-x86-mingw32\lib\mysql2\mysql2.rb
RUBY_VERSION =~ /(\d+.\d+)/
require "mysql2/#{$1}/mysql2" # <<-- this is that #2 line that throws an error
It is obvious that it takes the current Ruby version number and uses it as the path segment to reach some mysql2 file. In fact it is mysql2.so file. As I use Ruby 2.0.0 the path segment is 2.0:
mysql2/2.0/mysql2
Ok, now lets see how that directory of mysql2-0.3.11-x86-mingw32 gem looks like:
dir: C:\Ruby200\lib\ruby\gems\2.0.0\gems\mysql2-0.3.11-x86-mingw32\lib\mysql2\
No any 2.0/ directory.
I know the issue about libmysql.dll. I have it in my C:\Ruby200\bin. It doesn't help.
I read this answer https://stackoverflow.com/a/5368767/1114926 from the creator of RubyInstaller. I tried but it didn't help. It works for Ruby 1.9.3 because there is 1.9/ directory. But it doesn't work for Ruby 2.0.0.
How to solve it?
UPD 1:
Thank you for your answer. I've tried. Unfortunately I have ERROR: Failed to build gem native extension. error:
C:\>gem install mysql2 --platform=ruby
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
C:/Ruby200/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/Ruby200/bin/ruby
C:/Ruby200/lib/ruby/2.0.0/mkmf.rb:431:in `try_do': The compiler failed to generate an executable file. (Runtim
eError)
You have to install development tools first.
... other code follows here...
It says:
You have to install development tools first.
But I have full DevKit installed, RubyInstaller installs it. Can't understand what else does it need.
I've already posted an issue to mysql2 GitHub page https://github.com/brianmario/mysql2/issues/364. No answers yet.
Had the absolutely same issue on Windows 7 x64 with Ruby 2.0.0 and DevKit 4.7.
The following steps helped me.
gem uninstall mysql2
Download last MySQL connector from http://cdn.mysql.com/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip
Extract it to C:\connector-6.0.2
gem install mysql2 --platform=ruby -- '--with-mysql-lib="C:\connector-6.0.2\lib" --with-mysql-include="C:\connector-6.0.2\include" --with-mysql-dir="C:\connector-6.0.2"'
Or even shorter:
gem install mysql2 --platform=ruby -- --with-opt-dir="C:\connector-6.0.2"
uninstall mysql2-0.3.11-x86-mingw32, gems compiled before Ruby200 won't work. You have to compile it yourself.
If you run gem uninstall mysql2 and there is a non compiled version listed then just uninstall mysql2-0.3.11-x86-mingw32 - the compiled version else...
Installation
gem install mysql2 --platform=ruby. that would work.
Follow this guide on installing devkit http://rubyonwindowsguides.github.com/book/ch02-04.html.
Then try again.
Exactly the same behavior when I try to install Redmine on windows XP
when I try to do the "rake generate_secret_token", I got "cannot load
such file -- mysql2/2.0/mysql2 (LoadError)"
and when I try to re build mysql2 using --platform=ruby, I got the
same message as you green.
for the moment, I am stucked there ... but if anybody has anything to allow me to move forward, it will be very welcome.
I will keep informed as well
antoine
I almost done the same what #odiszapc described. Uninstall old gem, download mysql-connector-c-noinstall, unzip, but finally I used this command to build native gem:
gem install mysql2 --platform=ruby -- --with-opt-dir=/c/connector-6.0.2
(If you use git-bash then you can use unix style directory syntax.)
Copy paste from that link: https://github.com/brianmario/mysql2/issues/359. It worked for me.
If after installing the gem, you get an error:
"The specified module could not be found.
C:/Devel/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/lib/mysql2/mysql2.so"
That can be fixed by copying libmysql.dll to Ruby's bin folder.

RVM: Incorrect Ruby version referenced after removal

Just updated the version of Ruby (1.9.2 to 1.9.3) I have installed but now getting the following error when running rake:
$ rake
-bash: /Users/mike.simmonds/.rvm/gems/ruby-1.9.3-p0/bin/rake: /Users/mike.simmonds/.rvm/rubies/ruby-1.9.2-p180/bin/ruby: bad interpreter: No such file or directory
Any tips?
It appears reinstalling the rake gem has fixed it.
looks like a gem pristine task failed and you had older rvm, I have already changed the upgrade code to run upgrade for every gem separately and report you list of failed gems.
It's important to read outputs of rvm, even we try to automate things and make things very easy - sometimes there is not much we can do with the available tools.

Getting Rails working with a JS runtime environment

I'm using Ubuntu 11.10 and the terminal to install and run Rails. Here
is the process I've taken so far to setup Rails:
download and install Ruby 1.9.2 and Rails 3.1.0
-- I did this using sudo apt-get ruby1.9.1 and sudo gem install
rails
I made a new rails app using rails new path/to/app
I went to the new app directory and tried running rails server and got an
error about not having a JS ruby environment
I had to get a JS runtime environment for execjs so I downloaded 'therubyracer'
as well as 'therubyrhino' and added them to my gem file, one at a time like this:
gem
'therubyracer' then ran bundle install
After everything was successful with the install, I ran rails server again
-- with both runtime environments I have had similar errors:
Could not find libv8-3.3.10.4 in any of the sources
Run `bundle install` to install missing gems.
Could not find therubyrhino-1.73.0 in any of the sources
Run `bundle install` to install missing gems.
Bundle knows where these programs live, giving correct pathnames when I
enter bundle show libv8 or bundle show therubyrhino. They are both
in /usr/lib/ruby/gems/1.9.1/gems/_ where all the other gems are
located for the bundle install.
Does anyone know where this exception is coming up in the Rails source
code? Does anyone know how Rails is gathering the gems? Better yet,
anyone had this problem and know how to fix it?
Thanks so much,
Feav
Have you tried starting the server using bundle exec rails server?
This problem has been fixed in a newer version of Rails.

Project broken with Bundler errors after RVM install

I installed RVM and installed 3 different rubies: 1.8.7, ree, and 1.9.2.
I have a Rails 3.0.9 project that uses 1.8.7.
Now when I try to run the 3.0.9 project, I get this error:
Could not find xml-simple-1.1.0 in any of the sources
However, the following command:
bundle show xml-simple
yields:
/Users/me/.rvm/gems/ruby-1.8.7-p334/gems/xml-simple-1.1.0
Looks right to me. What am I missing here? The application, when running, is clearly not seeing the right path. Yet Bundler, when run at the command line, sees it just fine. I am not certain where these paths are to be set. I am admittedly new to RVM, I installed it because I want to start a new edge project with 1.9.2.
Thank you for any help you can provide.
I needed to learn how to create a gemset, then switch to that gemset. You can always check your gem and ruby environment with rvm using:
rvm info
That's what clued me in. Once I "use"d the appropriate gemset where the gem was installed, it worked great.