无法加载此类文件 - sqlite3(LoadError)

时间:2017-03-08 23:07:47

标签: ruby

我是一个完整的Ruby新手。我正在尝试加载sqlite3模块。这是 我的整个剧本:

#!/usr/bin/ruby -w
require 'sqlite3'

运行该命令会产生此输出:

/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- sqlite3 (LoadError)
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from ./sqlite.rb:2:in `<main>'

此问题的首页... seems to be this page。但是,这些解决方案都没有帮助。

最流行的解决方案是编辑sqlite3的gemspec文件。我只能找到 我的系统上的一个文件看起来像sqlite3的gemspec文件。它有以下相当奇怪的路径:

/home/terry/.gem/specs/api.rubygems.org%443/quick/Marshal.4.8/sqlite3-1.3.13.gemspec

该文件的内容如下所示(包装用于阅读):

;;F;U;  [[[I"~>;TU;[I"  3.15;T0I"jamis@37signals.com;TI"luislavena@gmail.com;TI"
aaron@tenderlovemaking.com;TI"Jamis Buck;TI"Luis Lavena;TI"Aaron Patterson;TI"▒
This module allows Ruby programs to interface with the SQLite3 database engine
(http://www.sqlite.org).  You must have the SQLite engine installed in order
to build this module.
Note that this module is only compatible with SQLite 3.6.16 or newer.;TI"
2https://github.com/sparklemotion/sqlite3-ruby;TT@[I" BSD-3;T

这与stackoverflow页面的描述不匹配。

所以我迷路了。

以下是我的一些系统规范:

Ubuntu Linux 16.04.1

# sqlite3 -version
3.11.0 2016-02-15 17:29:24 3d862f207e3adc00f78066799ac5a8c282430a5f

# ruby --version
 ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]

如果有其他信息我应该发布,请告诉我。任何帮助表示赞赏。谢谢!

- 更新 -

为了回应Amadan的建议,我尝试了建议的命令并得到了这个结果:

# gem install sqlite3
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /var/lib/gems/2.3.0 directory.

所以我用sudo试了一下并得到了这个:

# sudo gem install sqlite3
[sudo] password for terry:
Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3:
        ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/sqlite3-1.3.13/ext/sqlite3
/usr/bin/ruby2.3 -r ./siteconf20170308-16463-q46juc.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/sqlite3-1.3.13 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/gem_make.out

我检查了该日志文件,它只是有同样的错误。

- 另一次更新 -

在@maxple的建议下,我安装了ruby2.3-dev。这看起来很顺利:

# sudo apt-get install ruby2.3-dev
[sudo] password for terry:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libgmp-dev libgmpxx4ldbl
Suggested packages:
  gmp-doc libgmp10-doc libmpfr-dev
The following NEW packages will be installed:
  libgmp-dev libgmpxx4ldbl ruby2.3-dev
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,357 kB of archives.
After this operation, 6,493 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://nyc2.mirrors.digitalocean.com/ubuntu xenial/main amd64 libgmpxx4ldbl amd64 2:6.1.0+dfsg-2 [8,948 B]
Get:2 http://nyc2.mirrors.digitalocean.com/ubuntu xenial/main amd64 libgmp-dev amd64 2:6.1.0+dfsg-2 [314 kB]
Get:3 http://nyc2.mirrors.digitalocean.com/ubuntu xenial-updates/main amd64 ruby2.3-dev amd64 2.3.1-2~16.04 [1,034 kB]
Fetched 1,357 kB in 0s (3,228 kB/s)
Selecting previously unselected package libgmpxx4ldbl:amd64.
(Reading database ... 125914 files and directories currently installed.)
Preparing to unpack .../libgmpxx4ldbl_2%3a6.1.0+dfsg-2_amd64.deb ...
Unpacking libgmpxx4ldbl:amd64 (2:6.1.0+dfsg-2) ...
Selecting previously unselected package libgmp-dev:amd64.
Preparing to unpack .../libgmp-dev_2%3a6.1.0+dfsg-2_amd64.deb ...
Unpacking libgmp-dev:amd64 (2:6.1.0+dfsg-2) ...
Selecting previously unselected package ruby2.3-dev:amd64.
Preparing to unpack .../ruby2.3-dev_2.3.1-2~16.04_amd64.deb ...
Unpacking ruby2.3-dev:amd64 (2.3.1-2~16.04) ...
Processing triggers for libc-bin (2.23-0ubuntu5) ...
Setting up libgmpxx4ldbl:amd64 (2:6.1.0+dfsg-2) ...
Setting up libgmp-dev:amd64 (2:6.1.0+dfsg-2) ...
Setting up ruby2.3-dev:amd64 (2.3.1-2~16.04) ...
Processing triggers for libc-bin (2.23-0ubuntu5) ...

然后我再次尝试使用gem install sqlite3,这似乎并不顺利:

# sudo gem install sqlite3
Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3:
        ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/sqlite3-1.3.13/ext/sqlite3
/usr/bin/ruby2.3 -r ./siteconf20170308-16984-tcxs0x.rb extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'brew install sqlite3',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
*** 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
        --without-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=/usr/bin/$(RUBY_BASE_NAME)2.3
        --with-sqlite3-config
        --without-sqlite3-config
        --with-pkg-config
        --without-pkg-config
        --with-sqlite3-dir
        --without-sqlite3-dir
        --with-sqlite3-include
        --without-sqlite3-include=${sqlite3-dir}/include
        --with-sqlite3-lib
        --without-sqlite3-lib=${sqlite3-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/sqlite3-1.3.13 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/gem_make.out

日志文件mkmf.log包含:

package configuration for sqlite3 is not found
find_header: checking for sqlite3.h... -------------------- no

"gcc -o conftest -I/usr/include/x86_64-linux-gnu/ruby-2.3.0 -I/usr/include/ruby-2.3.0/ruby/backward -I/usr/include/ruby-2.3.0 -I. -Wdate-time -D_FORTIFY_SOURCE=2   -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC conftest.c  -L. -L/usr/lib/x86_64-linux-gnu -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic     -lruby-2.3  -lpthread -lgmp -ldl -lcrypt -lm   -lc"
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

"gcc -E -I/usr/include/x86_64-linux-gnu/ruby-2.3.0 -I/usr/include/ruby-2.3.0/ruby/backward -I/usr/include/ruby-2.3.0 -I. -Wdate-time -D_FORTIFY_SOURCE=2   -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC  conftest.c -o conftest.i"
conftest.c:3:21: fatal error: sqlite3.h: No such file or directory
compilation terminated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <sqlite3.h>
/* end */

--------------------

0 个答案:

没有答案