为什么在 Windows 上导入 ruby​​ pg gem 会失败?

时间:2021-03-11 16:18:17

标签: ruby postgresql rubygems pg

我在加载我在 Windows 上为 ruby​​ 安装的 gem(pg,一个用于 ruby​​ 的 postgreSQL API)时遇到问题。它已通过 gem install 成功安装。我为 pg gem 所需的 libpq 库和头文件下载了 Strawberry perl。我收到以下成功输出:

Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
Successfully installed pg-1.2.3
Parsing documentation for pg-1.2.3
Installing ri documentation for pg-1.2.3
Done installing documentation for pg after 7 seconds
1 gem installed

如果我运行 gem list,我可以看到 gem 也与其他 gem 一起安装:

gem list
> pg (1.2.3)

但是我无法使用 require 方法加载它。如果我尝试运行包含 require 'pg' 的脚本,我会收到以下错误:

C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:83:in `add_dll_directory_winapi': AddDllDirectory failed for C:/Ruby30-x        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:50:in `initialize'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `new'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `add_dll_directory'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:15:in `block in <top (required)>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:26:in `rescue in <top (required)>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:4:in `<top (required)>'
        from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `require'
        from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `rescue in require'
        from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149:in `require'
        from P:/Projekte/OPTIMA_910/Hydraulik/Scripts/pg_snippet.rb:2:in `<main>'
<internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require': 126: The specified module could not be found.   - C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg_ext.so (LoadError)
        from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:5:in `<top (required)>'
        from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `require'
        from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `rescue in require'
        from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149:in `require'
        from D:/Scripts/pg_snippet.rb:2:in `<main>'
<internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- pg (LoadError)
        from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from D:/Scripts/pg_snippet.rb:2:in `<main>'

同样,我尝试在 irb 上将其作为命令运行,但输出略有不同:

Traceback (most recent call last):
       14: from C:/Ruby30-x64/bin/irb.cmd:31:in `<main>'
       13: from C:/Ruby30-x64/bin/irb.cmd:31:in `load'
       12: from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/irb-1.3.0/exe/irb:11:in `<top (required)>'
       11: from (irb):2:in `<main>'
       10: from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149:in `require'
        9: from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `rescue in require'
        8: from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `require'
        7: from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:4:in `<top (required)>'
        6: from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:26:in `rescue in <top (required)>'
        5: from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:15:in `block in <top (required)>'
        4: from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `add_dll_directory'
        3: from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `new'
        2: from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:50:in `initialize'
        1: from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:83:in `add_dll_directory_winapi'
RubyInstaller::Runtime::DllDirectory::WinApiError (AddDllDirectory failed for C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/x64-mingw32)
irb(main):003:0> gem list
Traceback (most recent call last):
        5: from C:/Ruby30-x64/bin/irb.cmd:31:in `<main>'
        4: from C:/Ruby30-x64/bin/irb.cmd:31:in `load'
        3: from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/irb-1.3.0/exe/irb:11:in `<top (required)>'
        2: from (irb):2:in `<main>'
        1: from (irb):3:in `rescue in <main>'
NameError (undefined local variable or method `list' for main:Object)
irb(main):004:0> C:/Ruby30-x64/lib/ruby/3.0.0/reline/unicode.rb:124:in `calculate_width': undefined method `encode' for nil:NilClass (NoMethodError)
        from C:/Ruby30-x64/lib/ruby/3.0.0/reline/line_editor.rb:1314:in `calculate_width'
        from C:/Ruby30-x64/lib/ruby/3.0.0/reline/line_editor.rb:126:in `check_multiline_prompt'
        from C:/Ruby30-x64/lib/ruby/3.0.0/reline/line_editor.rb:365:in `rerender'
        from C:/Ruby30-x64/lib/ruby/3.0.0/reline.rb:248:in `block (3 levels) in inner_readline'
        from C:/Ruby30-x64/lib/ruby/3.0.0/reline.rb:246:in `each'
        from C:/Ruby30-x64/lib/ruby/3.0.0/reline.rb:246:in `block (2 levels) in inner_readline'
        from C:/Ruby30-x64/lib/ruby/3.0.0/reline.rb:330:in `block in read_io'
        from C:/Ruby30-x64/lib/ruby/3.0.0/reline.rb:284:in `loop'
        from C:/Ruby30-x64/lib/ruby/3.0.0/reline.rb:284:in `read_io'
        from C:/Ruby30-x64/lib/ruby/3.0.0/reline.rb:245:in `block in inner_readline'
        from C:/Ruby30-x64/lib/ruby/3.0.0/reline.rb:243:in `loop'
        from C:/Ruby30-x64/lib/ruby/3.0.0/reline.rb:243:in `inner_readline'
        from C:/Ruby30-x64/lib/ruby/3.0.0/reline.rb:175:in `readmultiline'
        from C:/Ruby30-x64/lib/ruby/3.0.0/forwardable.rb:238:in `readmultiline'
        from C:/Ruby30-x64/lib/ruby/3.0.0/forwardable.rb:238:in `readmultiline'
        from C:/Ruby30-x64/lib/ruby/3.0.0/irb/input-method.rb:302:in `gets'
        from C:/Ruby30-x64/lib/ruby/3.0.0/irb.rb:519:in `block (2 levels) in eval_input'
        from C:/Ruby30-x64/lib/ruby/3.0.0/irb.rb:721:in `signal_status'
        from C:/Ruby30-x64/lib/ruby/3.0.0/irb.rb:518:in `block in eval_input'
        from C:/Ruby30-x64/lib/ruby/3.0.0/irb/ruby-lex.rb:202:in `lex'
        from C:/Ruby30-x64/lib/ruby/3.0.0/irb/ruby-lex.rb:174:in `block (2 levels) in each_top_level_statement'
        from C:/Ruby30-x64/lib/ruby/3.0.0/irb/ruby-lex.rb:171:in `loop'
        from C:/Ruby30-x64/lib/ruby/3.0.0/irb/ruby-lex.rb:171:in `block in each_top_level_statement'
        from C:/Ruby30-x64/lib/ruby/3.0.0/irb/ruby-lex.rb:170:in `catch'
        from C:/Ruby30-x64/lib/ruby/3.0.0/irb/ruby-lex.rb:170:in `each_top_level_statement'
        from C:/Ruby30-x64/lib/ruby/3.0.0/irb.rb:537:in `eval_input'
        from C:/Ruby30-x64/lib/ruby/3.0.0/irb.rb:472:in `block in run'
        from C:/Ruby30-x64/lib/ruby/3.0.0/irb.rb:471:in `catch'
        from C:/Ruby30-x64/lib/ruby/3.0.0/irb.rb:471:in `run'
        from C:/Ruby30-x64/lib/ruby/3.0.0/irb.rb:400:in `start'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/irb-1.3.0/exe/irb:11:in `<top (required)>'
        from C:/Ruby30-x64/bin/irb.cmd:31:in `load'
        from C:/Ruby30-x64/bin/irb.cmd:31:in `<main>'

我希望我只需要指定一些额外的路径。顺便说一句,我也没有使用 rails。任何帮助将不胜感激!如果其他人对 pg 的替代方案有好的建议,我也可能愿意考虑。

提前致谢

0 个答案:

没有答案