【问题标题】:Rails 4.0rc1 app not running due to missing sqlite3 gem由于缺少 sqlite3 gem,Rails 4.0rc1 应用程序无法运行
【发布时间】:2013-05-07 00:54:58
【问题描述】:

我第一次尝试安装 Rails 4.0。在带有 Ruby 2.0 x64 的 Windows 8 上。冉:

gem install rails --version 4.0.0.rc1 --no-ri --no-rdoc

然后我运行:

rails new test_app
cd test_app
rails s

但是localhost:3000的网页报如下错误:

为数据库适配器指定了“sqlite3”,但未加载 gem。 将gem 'sqlite3' 添加到您的 Gemfile。

它在我的 Gemfile 中:

gem 'sqlite3'

我尝试运行 bundle install 几次,但它甚至没有将它列在所有其他 gem 中。

更新:我已经尝试以 2 种不同的方式安装 sqlite3 gem,都使用从 DevKit 的 msys.bat 文件打开的终端。下面提到的@szines 的方式给了我以下错误:

$ gem install sqlite3 --platform=ruby -- --with-opt-dir=c:/sqlite-amalgamation-3071602
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-opt-dir=c:/sqlite-amalgamation-3071602'
This could take a while...
ERROR:  Error installing sqlite3:
        ERROR: Failed to build gem native extension.

    c:/Ruby200-x64/bin/ruby.exe extconf.rb --with-opt-dir=c:/sqlite-amalgamation-3071602
checking for sqlite3.h... yes
checking for sqlite3_libversion_number()... -lsqlite3
sqlite3 is missing. Install SQLite3 from http://www.sqlite.org/ first.
*** 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
        --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-x64/bin/ruby
        --with-sqlite3-dir
        --without-sqlite3-dir
        --with-sqlite3-include
        --without-sqlite3-include=${sqlite3-dir}/include
        --with-sqlite3-lib
        --without-sqlite3-lib=${sqlite3-dir}/
        --enable-local
        --disable-local
        --with-sqlite3lib
        --without-sqlite3lib


Gem files will remain installed in c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7 for inspection.
Results logged to c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/ext/sqlite3/gem_make.out

另外,我使用来自 sqlite.org 的 autoconf 包,我能够编译和安装 sqlite3 gem。但是,当我尝试打开 Rails 服务器时,出现以下错误:

C:\Users\me\RubymineProjects\my_project>rails s
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/lib/sqlite3.rb:6:in `require': cannot load such file -- sqlite3/sqlite3_native (LoadError)
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/lib/sqlite3.rb:6:in `rescue in <top (required)>'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/lib/sqlite3.rb:2:in `<top (required)>'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
        from C:/Users/me/RubymineProjects/my_project/config/application.rb:7:in `<top (required)>'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:78:in `require'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:78:in `block in <top (required)>'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:75:in `tap'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:75:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

【问题讨论】:

标签: ruby-on-rails sqlite bundler ruby-on-rails-4


【解决方案1】:

很烦人,但我终于让它工作了。您基本上必须执行以下操作:

  1. 下载 Luis Lavena 的 sqlite files ready to be compiled(这是 x64)
  2. 使用 7-zip 解压缩到 `c:\sqlite3
  3. 从您将 DevKit 解压到的 DevKit 文件夹中运行 msys.bat
  4. 运行gem install sqlite3 --platform=ruby -- --with-opt-dir=C:/sqlite3

【讨论】:

    【解决方案2】:

    我在 Mac OS X 上运行 Rails 版本 4.0.0 和 Ruby 2.0,问题是 sqlite3 没有更新到兼容版本(警告也懒得说)。

    这是我解决问题的方法:

    $ gem install sqlite3 --platform=ruby
    

    这让我知道 sqlite3 的最新版本是 1.3.7。然后我相应地更新了 gemfile 中的 sqlite3 gem。就是这么简单。

    【讨论】:

      【解决方案3】:

      *此答案适用于 Ruby 2.0.0 x86,而不是 x64。

      我想我有。圣杯。奶与蜜之地。疯狂的灯光从印第安纳琼斯的那个盒子里射出来。不会在阳光下融化的冰淇淋。

      在这里尝试了几乎所有答案之后,最终为我做了什么(除非我产生幻觉)是https://stackoverflow.com/a/16524605/765352How do I install sqlite3 for Ruby on Windows? 中的最后一条评论)。

      我在 Windows 8 上运行 Ruby 2.0.0 x86,使用的是 RailsInstaller 版本的 Ruby。

      只是通过提供链接来详细说明他的答案:

      1. 转到http://www.sqlite.org(特别是http://sqlite.org/download.html)并下载:

      (我不知道是否需要最后两个。而且,我不会回到兔子洞去检查。)

      1. 将所有这些 ZIP 解压到您选择的目录中。我使用了“sqlite-amalgamation-301700”。 (目录)。

      2. 进入你的 ruby​​ shell,然后输入

        gem install sqlite3 --platform=ruby -- --with-sqlite3-dir=c:/sqlite-amalgamation-3071602 --with-sqlite3-include=c:/sqlite-amalgamation-3071602

      你应该看到

      C:\xx\>gem install sqlite3 --platform=ruby -- --with-sqlite3-dir=c:/sqlite-amalgamation-3071602 --with-sqlite3-include=c:/sqlite-amalgamation-3071602
      Temporarily enhancing PATH to include DevKit...
      Building native extensions with: '--with-sqlite3-dir=c:/sqlite-amalgamation-3071602 --with-sqlite3-include=c:/sqlite-amalgamation-3071602'
      This could take a while...
      Successfully installed sqlite3-1.3.7
      Parsing documentation for sqlite3-1.3.7
      unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/sqlite3/sqlite3_native.so, skipp
      ing
      Installing ri documentation for sqlite3-1.3.7
      Done installing documentation for sqlite3 (3 sec).
      1 gem installed
      

      嘘。拿那个,自动编译什么都没有。不用感谢 SQLITE,它被证明是重量级的。一如既往地感谢 Google。

      参考资料:

      • 这个帖子;

      • https://stackoverflow.com/a/16524605/765352的人;

      • 一堆讨论 sqlite.org 的线程;

      • StackExchange,感谢你没有放弃我;

      • 我,因为没有放弃 StackExchange;

      • 所有的信徒;

      • 我的制片人和经理,他们爱我(我爱你,Al)。

      【讨论】:

      • 这对我不起作用。除了使目录以 3071700 而不是像 gem install 命令中的那样以 3071602 结尾之外,我完美地完成了所有这些说明。
      • 我在 Windows 8 上使用 Ruby 2.0.0 x64。这也是你在上面使用的吗?
      • 您基本上缺少 lib 目录中的 .a 文件,这就是为什么它不适用于上述内容。
      • 以上确实有效。仅适用于 Windows 8 上的 Ruby 2 x86,而不适用于 Ruby 2 x64。我认为在 Ruby 2.0.0 上运行 Rails beta 就足够了,我不会同时升级到 64 位。我看到你解决了下面的 x64 问题。
      【解决方案4】:

      下载 sqlite 源文件,并使用特殊参数构建 sqlite gem。

      • 下载 sqlite 源代码。
      • 在您的 PC 上创建一个 sqlite 文件夹。例如:c:/sqlite
      • 在此文件夹中创建三个子文件夹:c:/sqlite/include、c:/sqlite/lib、c:/sqlite/bin
      • 复制源文件:

      c:/sqlite/bin =&gt; sqlite3.exe

      c:/sqlite/include =&gt; sqlite3.h sqlite3ext.h

      c:/sqlite/lib =&gt; libsqlite3.a sqlite3.la

      • 卸载之前的 sqlite gem

      gem uninstall sqlite3

      • 需要兼容的 DevKit,用于 64 位系统 x64 版本。
      • 使用以下命令安装兼容的 gem。 (不要忘记第二个空的双破折号。)

      gem install sqlite3 --platform=ruby -- --with-opt-dir=c:/sqlite

      请注意,如果您稍后运行 bundle update 命令并看到 bundler 安装了“官方”sqlite gem,则必须卸载“旧”版本。如果您有更多版本的 sqlite,无论如何您都会收到错误消息。

      【讨论】:

      • 感谢@szines 的解释。不幸的是,我仍然无法安装 gem。我在原始问题中详细说明了输出。
      • 您是否在 c:/sqlite-amalgamation-3071602 文件夹中创建了两个子文件夹?您应该有 c:/sqlite-amalgamation-3071602/lib 和 c:/sqlite-amalgamation-3071602/include ,它们包含如上所述的两两个文件。我还没有写,但是尝试下载二进制版本的 sqlite 并复制到你的 ruby​​ bin 目录和你的 windows 目录中,以确保你的路径中存在二进制文件。
      • 完全按照您的建议进行操作。还尝试在 bin 目录和 c:\windows 目录中添加 sqlite3.exe 二进制文件。我总是遇到同样的错误:sqlite3 is missing. Install SQLite3 from http://www.sqlite.org/ first. *** extconf.rb failed ***
      • 我用的是Ruby 2.0.0 x64,你也是用的吗?
      • 您基本上缺少 lib 目录中的 .a 文件
      【解决方案5】:

      看看这个分辨率:

      在这种情况下,最近的 Bundler 版本中存在错误。预发布的 Bundler 解决了这个问题。

      【讨论】:

        【解决方案6】:

        谢谢大家,这对我安装 sqlite3 有用:

        下载 sqlite-dll-win64-x64-3260000.zip 、 sqlite-tools-win32-x86-3260000.zip 和 sqlite-autoconf-3260000.tar.gz。

        将 sqlite3.h 和 sqlite3ext.h 放在名为 include

        的文件夹中

        将 shell.c、sqlite3.c、sqlite3.def 和 sqlite3.dll 放在名为 lib

        的文件夹中
        gem install sqlite3 --platform=ruby -- --with-sqlite3-lib=c:/Devkit/sqlite3/lib --with-sqlite3-include=c:/Devkit/sqlite3/include
        gem install data_mapper --platform=ruby -- --with-sqlite3-lib=c:/Devkit/sqlite3/lib --with-sqlite3-include=c:/Devkit/sqlite3/include
        gem install dm-sqlite-adapter --platform=ruby -- --with-sqlite3-lib=c:/Devkit/sqlite3/lib --with-sqlite3-include=c:/Devkit/sqlite3/include
        

        【讨论】:

          猜你喜欢
          • 2017-11-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-11-07
          • 1970-01-01
          • 2012-05-14
          • 1970-01-01
          相关资源
          最近更新 更多