macos Snow Leopard 和 Ruby on Rails - SQLite3 问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1350359/
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-10-21 06:22:03  来源:igfitidea点击:

Snow Leopard & Ruby on Rails - SQLite3 issue

ruby-on-railsmacos

提问by devinross

I just upgraded to snow leopard. Before, I had everything running fine, but now when I start the server from the terminal I get:

我刚刚升级到雪豹。之前,我一切正常,但现在当我从终端启动服务器时,我得到:

=> Booting WEBrick
=> Rails 2.3.3 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2009-08-28 23:18:19] INFO  WEBrick 1.3.1
[2009-08-28 23:18:19] INFO  ruby 1.8.7 (2008-08-11) [universal-darwin10.0]
[2009-08-28 23:18:19] INFO  WEBrick::HTTPServer#start: pid=845 port=3000

Then when I got to generated page, it seems like it isn't working with sqlite3. How do I fix? Here's what the server prints out when I go to a scripted view page:

然后当我到达生成的页面时,它似乎不适用于 sqlite3。我该如何解决?这是当我转到脚本视图页面时服务器打印的内容:

/!\ FAILSAFE /!\  Fri Aug 28 23:18:34 -0400 2009
  Status: 500 Internal Server Error
  uninitialized constant SQLite3::Driver::Native::Driver::API
    /Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:105:in `const_missing'
    /Library/Ruby/Gems/1.8/gems/sqlite3-ruby-1.2.5/lib/sqlite3/driver/native/driver.rb:76:in `open'
    /Library/Ruby/Gems/1.8/gems/sqlite3-ruby-1.2.5/lib/sqlite3/database.rb:76:in `initialize'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:13:in `new'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:13:in `sqlite3_connection'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `send'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `new_connection'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:245:in `checkout_new_connection'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:188:in `checkout'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `loop'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `checkout'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:183:in `checkout'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:98:in `connection'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:326:in `retrieve_connection'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in `retrieve_connection'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:in `connection'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/query_cache.rb:9:in `cache'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/query_cache.rb:28:in `call'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/head.rb:9:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/methodoverride.rb:24:in `call'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/params_parser.rb:15:in `call'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/session/cookie_store.rb:93:in `call'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/reloader.rb:29:in `call'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/failsafe.rb:26:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in `synchronize'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in `call'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/dispatcher.rb:106:in `call'
    /Library/Ruby/Gems/1.8/gems/rails-2.3.3/lib/rails/rack/static.rb:31:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:46:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:40:in `each'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:40:in `call'
    /Library/Ruby/Gems/1.8/gems/rails-2.3.3/lib/rails/rack/log_tailer.rb:17:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/content_length.rb:13:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/handler/webrick.rb:46:in `service'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/handler/webrick.rb:13:in `run'
    /Library/Ruby/Gems/1.8/gems/rails-2.3.3/lib/commands/server.rb:111
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    script/server:3

回答by askegg

If you upgraded from Leopard, then you will need to reinstall the sqlite3-ruby gem. First install XCode, then run:

如果您从 Leopard 升级,那么您将需要重新安装 sqlite3-ruby gem。首先安装 XCode,然后运行:

sudo gem install sqlite3-ruby

回答by Marc

if you install the UNIX Dev Tools from the XCode installer, this should include the necessary header files (ruby.h).

如果您从 XCode 安装程序安装 UNIX Dev Tools,这应该包括必要的头文件 (ruby.h)。

回答by user210977

sudo port install sqlite3 sudo gem install sqlite3-ruby

须藤端口安装 sqlite3 须藤宝石安装 sqlite3-ruby

回答by nchaugen

Another possible cause for this problem is continuing to use Ruby versions installed with rvm (http://rvm.beginrescueend.com/) on Leopard after upgrading to Snow Leopard.

此问题的另一个可能原因是在升级到 Snow Leopard 后,继续在 Leopard 上使用与 rvm ( http://rvm.beginrescueend.com/)一起安装的 Ruby 版本。

Ruby versions installed with rvm are built from source and needs to be reinstalled on Snow Leopard to work with the sqlite3-ruby gem.

使用 rvm 安装的 Ruby 版本是从源代码构建的,需要在 Snow Leopard 上重新安装才能与 sqlite3-ruby gem 一起使用。

回答by graza

I had a similar issue. If you look at the stack backtrace, you can see that the file throwing the error is within sqlite-ruby itself:

我有一个类似的问题。如果查看堆栈回溯,您可以看到抛出错误的文件在 sqlite-ruby 内部:

def open( filename, utf16=false )
  API.send( utf16 ? :sqlite3_open16 : :sqlite3_open, filename )
end

So the API class is missing. At top of this file is the following code which suggests that the API class comes from requiring the sqlite3_api file:

所以缺少 API 类。在这个文件的顶部是以下代码,它表明 API 类来自需要 sqlite3_api 文件:

begin
  require 'sqlite3_api'
rescue LoadError
  if RUBY_PLATFORM =~ /mingw|mswin/ then
    RUBY_VERSION =~ /(\d+.\d+)/
    require "#{}/sqlite3_api"
  end
end

As you can see, this code will ignore a LoadError on platforms other than mingw/mswin. This is bad, and something I would consider a bug in the sqlite3-ruby gem. To figure out what's wrong, try requiring sqlite3_api in irb:

如您所见,此代码将忽略 mingw/mswin 以外平台上的 LoadError。这很糟糕,我认为这是 sqlite3-ruby gem 中的一个错误。要找出问题所在,请尝试在 irb 中要求 sqlite3_api:

$ irb
irb(main):001:0> require 'sqlite3_api'
LoadError: Unable to find library 'libsqlite3.so.8'. - /path/to/ruby/lib/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5/lib/sqlite3_api.sl
        from (irb):1:in `require'
        from (irb):1
        from /path/to/ruby/bin/irb:12:in `<main>'
irb(main):002:0>

YMMV, but for me, I realised that I was missing something in my shared-library path. Once I corrected that, everything worked.

YMMV,但对我来说,我意识到我在共享库路径中遗漏了一些东西。一旦我纠正了这一点,一切都奏效了。

回答by Kevin

For some reason, this didn't work too well for me.

出于某种原因,这对我来说效果不佳。

I had to basically start from scratch, following these instructions: http://hivelogic.com/articles/ruby-rails-leopardfrom the "Setting Up" stage.

我必须从头开始,遵循以下说明:http: //hivelogic.com/articles/ruby-rails-leopard从“设置”阶段开始。

  • Install XCode
  • Download Ruby 1.8.7
  • Recompile and install (I think this was the magic step I was missing)
  • Download Rubygems 1.3.5 (1.3.6 has some things deprecated that I didn't want to deal with)
  • Recompile and install Rubygems
  • THEN uninstall sqlite3: sudo gem uninstall sqlite3-ruby
  • Reinstall it: sudo gem install sqlite3-ruby
  • 安装 XCode
  • 下载 Ruby 1.8.7
  • 重新编译并安装(我认为这是我遗漏的神奇步骤)
  • 下载 Rubygems 1.3.5(1.3.6 有一些我不想处理的已弃用的东西)
  • 重新编译并安装 Rubygems
  • 然后卸载 sqlite3: sudo gem 卸载 sqlite3-ruby
  • 重新安装: sudo gem install sqlite3-ruby

To be clear, I tried the steps above. I tried installing XCode. I tried recompiling Rubygems...Only when I recompiled Ruby itself, THEN Rubygems, THEN uninstall and reinstall sqlite3-ruby did things clear up.

为了清楚起见,我尝试了上述步骤。我尝试安装 XCode。我尝试重新编译 Rubygems...只有当我重新编译 Ruby 本身,然后 Rubygems,然后卸载并重新安装 sqlite3-ruby 时,事情才清楚。

I hope this helps.

我希望这有帮助。

回答by Patrick Sereno

I've done all this... the only thing that has worked for me is

我已经完成了这一切......唯一对我有用的是

sudo env ARCHFLAGS="-arch x86_64" gem install sqlite3-ruby

Note: I did have XCode installed from devloper.apple.com, not the CD. The CD install of XCode Tools did nothing to fix this problem for me.

注意:我确实从 devloper.apple.com 安装了 XCode,而不是 CD。XCode Tools 的 CD 安装并没有为我解决这个问题。

If you don't have any XCode installed, you may need to get XCode 3 or 4 from http://developer.apple.com/xcode. You will need to sign up for an account. Presently, you may download XCode 3 for free without paying the $99 annual fee.

如果您没有安装任何 XCode,您可能需要从http://developer.apple.com/xcode获取 XCode 3 或 4 。您需要注册一个帐户。目前,您可以免费下载 XCode 3,而无需支付 99 美元的年费。

回答by TheArtTrooper

I just ran into this problem. This is what I ended up doing:

我刚刚遇到了这个问题。这就是我最终做的:

rm -fr ~/.gem
sudo gem install rails
sudo gem install sqlite3-ruby

rm -fr ~/.gem
sudo gem install rails
sudo gem install sqlite3-ruby

Now my rails/sqlite3 app is running again.

现在我的 rails/sqlite3 应用程序再次运行。

回答by Fousa

You should re-install XCode from the Snow Leopard DVD. This should fix the linkage problem!

您应该从 Snow Leopard DVD 重新安装 XCode。这应该可以解决链接问题!