Rails - 无法运行app:无法加载EventMachine C扩展;

时间:2013-02-12 01:53:06

标签: ruby-on-rails ruby bundler eventmachine

当我在Lion OS X上运行应用程序时,我收到此错误:

Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-1.0.0/lib/eventmachine.rb:8:in `require': no such file to load -- rubyeventmachine (LoadError)
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-1.0.0/lib/eventmachine.rb:8:in `<top (required)>'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in require'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
    from /Users/adam/rubydev/future_computers/config/application.rb:7:in `<top (required)>'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands.rb:53:in `require'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands.rb:53:in `block in <top (required)>'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands.rb:50:in `tap'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'adam

我真的不知道如何解决这个问题,我已将eventmachine gem添加到Gemfile中,但它没有帮助......

请帮助我,请问如何解决?

谢谢

5 个答案:

答案 0 :(得分:18)

在我的情况下,这修复了它:

  • $ gem uninstall eventmachine
  • 在提示符下告诉它卸载所有版本(它告诉你依赖关系)
  • $ bundle install

我正在阅读https://github.com/eventmachine/eventmachine/issues/333。事件机器存在问题,因此确保我获得最新版本似乎是一个好主意。

答案 1 :(得分:9)

对我来说,从tweaked config的来源编译eventmachine有帮助。尝试:

卸载eventmachine(如果已安装):

gem uninstall eventmachine

获取eventmachine来源:

git clone https://github.com/eventmachine/eventmachine.git
cd eventmachine

ext/extconf.rb

之后添加ext/fastfilereader/extconf.rb来修改CONFIG['CXX'] = "g++"require 'mkmf'个文件

编译并安装gem:

rake gem
gem install pkg/eventmachine-1.0.3.gem

现在eventmachine应该可以正常工作:)

答案 2 :(得分:2)

消息所说的最简单的修复只是require 'em/pure_ruby'。我想你可以把它放在 config / inlitializers 文件夹中,你可以调用文件 event_machine.rb

但它的性能与C扩展名不同。

答案 3 :(得分:0)

提供另一种解决方案,因为我浪费时间来追踪这个问题。我正在做bundle install --deployment,然后将结果提交到git中的一个单独的分支,这样我就可以直接将这个分支部署到服务器而无需再次执行bundle install

问题是eventmachine中有一个.gitignore文件告诉git忽略所有*.so个文件。因此,当我提交时,.so文件没有提交,并且不会在git status中显示为未跟踪。此外,由于gemspec存在,bundle认为包已完全安装。

我的解决方案是在构建过程中添加一个命令,以便在提交之前查看gems中的所有.gitignore个文件。

答案 4 :(得分:0)

您可能会在安装gem时遇到各种错误,或者尝试找到因ruby-devel未安装而导致ruby应用程序安装失败的解决方案。

我刚安装在我的Kali linux上

sudo apt-get install ruby​​-dev

一切都解决了。我试图安装bettercap。

这个答案有帮助:https://stackoverflow.com/a/4502672/6503117