无法加载此类文件——在 ruby​​ on rails 上的 sqlite3/sqlite3_native (LoadError)

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

cannot load such file -- sqlite3/sqlite3_native (LoadError) on ruby on rails

ruby-on-railssqlite

提问by Penchala Reddy Audireddy

When I try to setup basic installation and initiation of server using Rails 4.0.0 on Ruby 2.0.0, I'm facing the following error message.

当我尝试在 Ruby 2.0.0 上使用 Rails 4.0.0 设置服务器的基本安装和启动时,我遇到以下错误消息。

/usr/local/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 /usr/local/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/lib/sqlite3.rb:6:in `rescue in <top (required)>'
    from /usr/local/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/lib/sqlite3.rb:2:in `<top (required)>'
    from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
    from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
    from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
    from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
    from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
    from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
    from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
    from /home/penchal/new/site/config/application.rb:7:in `<top (required)>'
    from /usr/local/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:76:in `require'
    from /usr/local/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:76:in `block in <top (required)>'
    from /usr/local/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
    from /usr/local/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

How can I avoid this error message and proceed further?

如何避免此错误消息并继续进行?

回答by Harish Gopalakrishnan

Find your sqlite3 gemspec file. One example is /usr/local/share/gem/specifications/sqlite3-1.3.7.gemspec

找到您的 sqlite3 gemspec 文件。一个例子是 /usr/local/share/gem/specifications/sqlite3-1.3.7.gemspec

Windows: C:\Ruby21\lib\ruby\gems\2.1.0\specifications.

窗户: C:\Ruby21\lib\ruby\gems\2.1.0\specifications

You should adjust according with your Rubygem path and sqlite3 version. Edit the file above and look for the following line

您应该根据您的 Rubygem 路径和 sqlite3 版本进行调整。编辑上面的文件并查找以下行

s.require_paths=["lib"]

change it to

将其更改为

s.require_paths= ["lib/sqlite3_native"]

回答by hwding

see:https://stackoverflow.com/a/39136421/6755206

见:https://stackoverflow.com/a/39136421/6755206

fortunately, you don't have to switch to ruby 2.0
there is a solution to this issue, after endless trying...

幸运的是,你不必切换到 ruby​​ 2.0
,这个问题有一个解决方案,经过无尽的尝试......

https://github.com/hwding/sqlite3-ruby-win

https://github.com/hwding/sqlite3-ruby-win



Steps

脚步

Pre

  • gem uninstall sqlite3 --all
  • gem uninstall sqlite3 --all

Source

来源

Build

建造

  • run command-line in the extracted dir
  • make sure you have your C compiler installed and added to PATH
  • gem install bundler
  • bundle install
  • rake native gem
  • you'll find a dir named 'pkg' generated
  • 在提取的目录中运行命令行
  • 确保您已安装 C 编译器并将其添加到 PATH
  • gem install bundler
  • bundle install
  • rake native gem
  • 你会发现一个名为“pkg”的目录生成

Install

安装

  • enter dir 'pkg'
  • gem install --local sqlite3-xxx.gem('xxx' is version code)
  • 输入目录'pkg'
  • gem install --local sqlite3-xxx.gem('xxx' 是版本号)

Check

查看

  • irb
  • require 'sqlite3'
  • irb
  • require 'sqlite3'

回答by Lars Kanis

Since pull request #229has been merged, sqlite3 can be installed per git:key. It's possible to use sqlite3 easily through this addition in your Gemfile:

由于已合并拉取请求 #229,因此可以git:按键安装 sqlite3 。通过在您的以下内容中添加以下内容,可以轻松使用 sqlite3 Gemfile

gem 'sqlite3', git: "https://github.com/sparklemotion/sqlite3-ruby"

This works on RubyInstaller-2.4 and newer. It automatically installs the required pacman package mingw-w64-x86_64-sqlite3when you run bundler install.

这适用于 RubyInstaller-2.4 和更新版本。它会mingw-w64-x86_64-sqlite3在您运行时自动安装所需的 pacman 包bundler install

There are some more hints for Rails on Windows in the RubyInstaller2 FAQ.

RubyInstaller2 FAQ中有更多关于 Windows 上 Rails 的提示。

回答by Edson Momm

gem uninstall sqlite3 --all
ridk exec pacman -S mingw-w64-x86_64-sqlite3
gem inst sqlite3 --platform ruby

This solved the problem to me.

这解决了我的问题。

Windows 10
Ruby 2.5.3
Rails 5.2.2

回答by Ram

Just edit Gemfile and add gem 'sqlite3', platform: :ruby.

只需编辑 Gemfile 并添加 gem 'sqlite3', platform: :ruby.

回答by Norman Se?ler

No compiling of the sources or downloading pre-compiled libraries will solve this problem, believe me I tried everything, the problem lies somewhere else. This is how it works on windows:

没有编译源代码或下载预编译库可以解决这个问题,相信我,我尝试了一切,问题出在其他地方。这是它在 Windows 上的工作方式:

bundle update sqlite3

bundle update sqlite3

You likely get another similar error after this one regarding nokogiri, fix it with the command:

在这个关于 nokogiri 的错误之后,您可能会遇到另一个类似的错误,请使用以下命令修复它:

bundle update nokogiri

bundle update nokogiri

Enjoy your Ruby App!

享受您的 Ruby 应用程序!

回答by HymanHasaKeyboard

Uninstalling and reinstalling the sqlite3 gem worked for me.

卸载并重新安装 sqlite3 gem 对我有用。

gem uninstall sqlite3

bundle

回答by Bolan Oluwa

This worked for me:

这对我有用:

gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"

回答by Pradeep Sapkota

BEST OFFICIAL INSTALL

最佳官方安装

Im using rails 5.2.1p57, Windows 10 Just running following lines sloved the problem

我使用 rails 5.2.1p57,Windows 10 只需运行以下几行即可解决问题

gem uninstall sqlite3

and uninstall all installed versions. again execute following command

并卸载所有已安装的版本。再次执行以下命令

gem install sqlite3 --platform=ruby

You are now done. Let me know if problem persist.

你现在已经完成了。如果问题仍然存在,请告诉我。

回答by Andrew Britton

If the top answer doesn't work, a fix that I discovered is simply going to your Gemfile and adding the version number 1.3.11 (instead of 1.3.9) right after sqlite3. So the line in your Gemfile should now read:

如果最重要的答案不起作用,我发现的一个修复程序只是转到您的 Gemfile 并在 sqlite3 之后添加版本号 1.3.11(而不是 1.3.9)。所以你的 Gemfile 中的行现在应该是:

# Use sqlite3 as the database for Active Record
gem 'sqlite3',  '1.3.11'