【问题标题】:cannot load such file — sqlite3/sqlite3_native (LoadError) Ruby on Rails无法加载此类文件 — sqlite3/sqlite3_native (LoadError) Ruby on Rails
【发布时间】:2018-10-19 07:44:48
【问题描述】:

我查看了其他几篇关于此的帖子并尝试了解决方案但没有成功。

问题被标记为与此解决方案重复 cannot load such file -- sqlite3/sqlite3_native (LoadError) on ruby on rails 但给出的答案对我不起作用。我只是遇到了同样的错误

我刚刚安装了 rails,所以一切都是最新的 我正在使用以下版本:Windows 10,ruby 版本 2.5.1,rails 版本 5.2.0

还尝试使用包更新来更新 SQLite gem。

这是错误:

C:\proje>rails s

Traceback (most recent call last):

        43: from bin/rails:4:in `<main>'

        42: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'

        41: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'

        40: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'

        39: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'

        38: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'

        37: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'

        36: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'

        35: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'

        34: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/commands.rb:18:in `<top (required)>'

        33: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/command.rb:46:in `invoke'

        32: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/command/base.rb:65:in `perform'

        31: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'

        30: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'

        29: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'

        28: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/commands/server/server_command.rb:142:in `perform'

        27: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/commands/server/server_command.rb:142:in `tap'

        26: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/commands/server/server_command.rb:145:in `block in perform'

        25: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'

        24: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'

        23: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'

        22: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'

        21: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'

        20: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'

        19: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'

        18: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'

        17: from C:/proje/config/application.rb:7:in `<top (required)>'

        16: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bundler-1.16.1/lib/bundler.rb:114:in `require'

        15: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `require'

        14: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `each'

        13: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `block in require'

        12: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `each'

        11: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:81:in `block (2 levels) in require'

        10: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:79:in `require'

         9: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:70:in `require_with_bootsnap_lfi'

         8: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'

         7: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:71:in `block in require_with_bootsnap_lfi'

         6: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:71:in `require'

         5: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb:2:in `<top (required)>'

         4: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb:6:in `rescue in <top (required)>'

         3: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'

         2: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'

         1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'

C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require': cannot load such file -- sqlite3/sqlite3_native (LoadError)



C:\proje>

我该如何继续?

编辑:添加 Gemfile

source 'https://rubygems.org'

    git_source(:github) do |repo_name|
      repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
      "https://github.com/#{repo_name}.git"
    end


    # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
    gem 'rails', '~> 5.0.7'
    # Use sqlite3 as the database for Active Record
    gem 'sqlite3'
    # Use Puma as the app server
    gem 'puma', '~> 3.0'
    # Use SCSS for stylesheets
    gem 'sass-rails', '~> 5.0'
    # Use Uglifier as compressor for JavaScript assets
    gem 'uglifier', '>= 1.3.0'
    # Use CoffeeScript for .coffee assets and views
    gem 'coffee-rails', '~> 4.2'
    # See https://github.com/rails/execjs#readme for more supported runtimes
    # gem 'therubyracer', platforms: :ruby

    # Use jquery as the JavaScript library
    gem 'jquery-rails'
    # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
    gem 'turbolinks', '~> 5'
    # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
    gem 'jbuilder', '~> 2.5'
    # Use Redis adapter to run Action Cable in production
    # gem 'redis', '~> 3.0'
    # Use ActiveModel has_secure_password
    # gem 'bcrypt', '~> 3.1.7'

    # Use Capistrano for deployment
    # gem 'capistrano-rails', group: :development

    group :development, :test do
      # Call 'byebug' anywhere in the code to stop execution and get a debugger console
      gem 'byebug', platform: :mri
    end

    group :development do
      # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
      gem 'web-console', '>= 3.3.0'
    end

    # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
    gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

【问题讨论】:

  • 默认情况下,Rails 仅与Sqllite 捆绑在一起,因此不会造成任何问题。你能在Gemfile.lock 中搜索Sqllite gem 并发布当前安装的版本吗?
  • 这个问题是重复的,是的,但正如我在帖子中所说,我已经看过那个答案,但它没有用
  • 在您的 gem 文件中添加行 ruby '2.5.1'。它可能会起作用。即使它有效,它也不是永久修复。试试这个,让我知道。我们继续前进。
  • 尝试在run as a administrator 模式下运行命令提示符然后尝试

标签: ruby-on-rails ruby sqlite


【解决方案1】:

这应该对你有用,因为我遇到了完全相同的问题。确保你的 gemfile 中有这个:

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

在写这篇文章时,我可以确认这对我有用。

编辑:为了参考和跟踪问题,请密切关注:https://github.com/sparklemotion/sqlite3-ruby/pull/229

如您所见,他们在 6 天前合并了修复程序,但我认为 repo 上的 CD/CI 标记表示构建失败,因此他们尚未在 gem 中发布修复程序。 现在只需将分支称为源即可。

【讨论】:

  • 谢谢,它工作正常。出乎意料的是,Ver有错误但仍然发布。
【解决方案2】:

在带有 chefdk 的 Windows 上 1) 从原站点下载 sqlite3.h/sqlite3.dll 2) gem install sqlite3 --platform ruby​​ -- --with-opt-include=C:/sqlitedir --with-sqlite3-dir=C:/sqlitedir --with-sqlite3-lib=C:/sqlitedir

【讨论】:

  • 3) 将 sqlite3.dll 放到路径中
【解决方案3】:

不要让您在 Windows 10 中的生活变得复杂。

安装bash

  1. 打开 Microsoft Store
  2. 查找并安装 Ubuntu
  3. 运行它,然后你就可以安装 ruby​​/rails 等了。

因此您可以使用所有功能而不会出现特定于 Windows 的问题。

【讨论】:

  • 运行 Linux 子系统有它自己的注意事项和问题(特别是如果发布者不熟悉 Linux)。它也可能不是一个选项,因为我们不知道海报的要求。
猜你喜欢
  • 2013-07-12
  • 1970-01-01
  • 2018-08-19
  • 1970-01-01
  • 2019-02-02
  • 2013-03-25
  • 2013-03-21
相关资源
最近更新 更多