无法运行需要'nokogiri'的rake任务

时间:2013-06-03 12:01:42

标签: ruby rubygems rake nokogiri

我们有一个rake任务在数据库系统之间运行复杂的转换。我们已经升级了任务,现在需要Nokogiri。它安装了:

`gem list --local`:

*** LOCAL GEMS ***

...
nokogiri (1.5.9)
...

Ruby是1.8.x版本,需要require 'rubygems'

`ruby -v`
ruby 1.8.7 (2012-02-08 MBARI 8/0x8770 on patchlevel 358) [i686-linux], MBARI 0x8770, Ruby Enterprise Edition 2012.02

使用irb,一切似乎都很好:

`irb`
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'nokogiri'
=> true
irb(main):003:0>

然而,启动rake任务,它似乎找不到nokogiri:

lib/tasks$ RAILS_ENV="test" rake redmine::migrate_from_buggy_new.rake 280 --trace
(in /var/www/redmine)
rake aborted!
no such file to load -- nokogiri
/var/www/redmine/lib/tasks/migrate_from_buggy_new.rake:27:in `require'
/var/www/redmine/lib/tasks/migrate_from_buggy_new.rake:27
/usr/local/lib/ruby/gems/1.8/gems/railties-3.2.12/lib/rails/engine.rb:425:in `load'
/usr/local/lib/ruby/gems/1.8/gems/railties-3.2.12/lib/rails/engine.rb:425:in `load_tasks'
/usr/local/lib/ruby/gems/1.8/gems/railties-3.2.12/lib/rails/engine.rb:425:in `each'
/usr/local/lib/ruby/gems/1.8/gems/railties-3.2.12/lib/rails/engine.rb:425:in `load_tasks'
/usr/local/lib/ruby/gems/1.8/gems/railties-3.2.12/lib/rails/application.rb:145:in `load_tasks'
/usr/local/lib/ruby/gems/1.8/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `send'
/usr/local/lib/ruby/gems/1.8/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
/var/www/redmine/Rakefile:7
/usr/local/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/rake_module.rb:25:in `load'
/usr/local/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/rake_module.rb:25:in `load_rakefile'
/usr/local/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:583:in `raw_load_rakefile'
/usr/local/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:89:in `load_rakefile'
/usr/local/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:88:in `load_rakefile'
/usr/local/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:72:in `run'
/usr/local/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/usr/local/lib/ruby/gems/1.8/gems/rake-10.0.3/bin/rake:33
/usr/local/bin/rake:19:in `load'
/usr/local/bin/rake:19

我不知道下一步该怎么做,我在Ruby环境中很新鲜,而且一切都很奇怪而且很新。

编辑:rake文件的开头如下所示:

require 'active_record'
require 'action_controller'
require 'iconv'
require 'pp'

require 'rubygems'
require 'nokogiri'

namespace :redmine do
  desc 'Buggy migration script'
  task :migrate_from_buggy => :environment do

编辑2:Nokogiri已安装到/usr/local/lib/ruby/gems/1.8/gems/nokogiri-1.5.9/lib/nokogiri。我试图将它包含在搜索路径中,如下所示:

RAILS_ENV="test" rake redmine::migrate_from_buggy_new.rake 280 -I "/usr/local/lib/ruby/gems/1.8/gems/"
RAILS_ENV="test" rake redmine::migrate_from_buggy_new.rake 280 -I "/usr/local/lib/ruby/gems/1.8/gems/nokogiri-1.5.9"
RAILS_ENV="test" rake redmine::migrate_from_buggy_new.rake 280 -I "/usr/local/lib/ruby/gems/1.8/gems/nokogiri-1.5.9/lib"
RAILS_ENV="test" rake redmine::migrate_from_buggy_new.rake 280 -I "/usr/local/lib/ruby/gems/1.8/gems/nokogiri-1.5.9/lib/nokogiri"

一切都无济于事(同样的问题/错误信息)。

1 个答案:

答案 0 :(得分:1)

建议:如果您的环境完全可行,请考虑使用Bundler。它倾向于使许多这些噩梦般的宝石问题消失。