我在尝试在OSX(Leopard)上运行以下ruby脚本时遇到了麻烦。
require 'sqlite3'
database = SQLite3::Database.new( "new.database" )
database.execute( "create table sample_table (id INTEGER PRIMARY KEY, sample_text TEXT, sample_number NUMERIC);" )
database.execute( "insert into sample_table (sample_text,sample_number) values ('Sample Text1', 123)")
database.execute( "insert into sample_table (sample_text,sample_number) values ('Sample Text2', 456)")
rows = database.execute( "select * from sample_table" )
p rows
但是我收到以下错误:
/Users/Ted/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- sqlite3/sqlite3_native (LoadError)
from /Users/Ted/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/Ted/.rvm/gems/ruby-1.9.2-p180/gems/sqlite3-1.3.4/lib/sqlite3.rb:6:in `rescue in <top (required)>'
from /Users/Ted/.rvm/gems/ruby-1.9.2-p180/gems/sqlite3-1.3.4/lib/sqlite3.rb:2:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:33:in `require'
from <internal:lib/rubygems/custom_require>:33:in `rescue in require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from sequelsample.rb:1:in `<main>'
如何解决此问题?我使用ruby 1.9.2p180(2011-02-18修订版30909)[i386-darwin9.8.0]的命令安装了以下宝石:
sudo gem install sqlite3-ruby -- --with-sqlite3-dir=/sw
sudo gem install sqlite3 -- --with-sqlite3-dir=/sw
sqlite3 (1.3.4)
sqlite3-ruby (1.3.3)
答案 0 :(得分:9)
使用以下命令修复它:
gem uninstall sqlite3
gem uninstall sqlite3-ruby
sudo gem install sqlite3 -- --with-sqlite3-dir=/sw
泰德