【问题标题】:Error cannot load 'pg' gem on local windows 7 Ruby on Rails错误无法在本地 Windows 7 Ruby on Rails 上加载“pg”gem
【发布时间】:2013-06-20 18:51:48
【问题描述】:

我刚开始在 Rails 上学习 Ruby。我安装了 pg gem,如下所示。 'pg' 在 gemfile.lock 和 gemfile 中。但是,它不断收到错误,“gem 未加载,将 gem 'pg' 添加到您的 Gemfile。”

我也试过听从别人的建议,删除 gemfile.lock 并重新捆绑。同样的错误出来了。

E:\RoR docs\first_app>bundle show pg
Could not find gem 'pg'.
Did you mean pg?

宝石文件:

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0.rc2'

# Use sqlite3 as the database for Active Record
gem 'pg'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0.rc2'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the app server
# gem 'unicorn'

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

# Use debugger
# gem 'debugger', group: [:development, :test]

数据库.yml:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: postgresql
  database: first_app
  pool: 5
  username: postgres
  password: admin
  port: 5432
  timeout: 5000
  host: localhost

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

宝石清单:

*** LOCAL GEMS ***

actionmailer (4.0.0.rc2, 3.2.13)
actionpack (4.0.0.rc2, 3.2.13)
activemodel (4.0.0.rc2, 3.2.13)
activerecord (4.0.0.rc2, 3.2.13)
activerecord-deprecated_finders (1.0.3)
activerecord-postgresql-adapter (0.0.1)
activeresource (3.2.13)
activesupport (4.0.0.rc2, 3.2.13)
ansi (1.4.3)
arel (4.0.0, 3.0.2)
atomic (1.1.9)
bigdecimal (1.2.0)
builder (3.2.2, 3.1.4, 3.0.4)
bundler (1.3.5)
capybara (2.1.0)
coffee-rails (4.0.0, 3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.6.2)
diff-lcs (1.2.4)
erubis (2.7.0)
execjs (1.4.0)
formatador (0.2.4)
guard (1.8.1)
guard-rspec (3.0.2)
hike (1.2.3)
i18n (0.6.4, 0.6.1)
io-console (0.4.2)
jason (0.6.0)
jbuilder (1.4.2)
journey (1.0.4)
jquery-rails (3.0.1)
json (1.8.0, 1.7.7)
listen (1.2.2)
lumberjack (1.0.3)
mail (2.5.4)
mime-types (1.23)
mini_portile (0.5.0)
minitest (5.0.4, 4.7.4, 4.3.2)
multi_json (1.7.7)
pg (0.15.1 x64-mingw32)
pik (0.2.8)
polyglot (0.3.3)
psych (2.0.0)
rack (1.5.2, 1.4.5)
rack-cache (1.2)
rack-ssl (1.3.3)
rack-test (0.6.2)
rails (4.0.0.rc2, 3.2.13)
railties (4.0.0.rc2, 3.2.13)
rake (10.1.0, 0.9.6)
rb-fsevent (0.9.3)
rb-inotify (0.9.0)
rb-kqueue (0.2.0)
rdiscount (2.1.6)
rdoc (4.0.1, 4.0.0, 3.12.2)
rspec (2.13.0)
rspec-core (2.13.1)
rspec-expectations (2.13.0)
rspec-mocks (2.13.1)
rspec-rails (2.13.2)
sass (3.2.9)
sass-rails (4.0.0.rc2, 3.2.6)
sdoc (0.3.20)
sprockets (2.10.0, 2.2.2)
sprockets-rails (2.0.0)
test-unit (2.5.5, 2.0.0.0)
thor (0.18.1)
thread_safe (0.1.0)
tilt (1.4.1)
treetop (1.4.14)
turbolinks (1.2.0)
turn (0.9.6, 0.8.2)
tzinfo (1.0.0, 0.3.37)
uglifier (2.1.1)
xpath (2.0.0)

捆绑:

E:\RoR docs\first_app>bundle
Using rake (10.1.0)
Using i18n (0.6.4)
Using minitest (4.7.4)
Using multi_json (1.7.7)
Using atomic (1.1.9)
Using thread_safe (0.1.0)
Using tzinfo (0.3.37)
Using activesupport (4.0.0.rc2)
Using builder (3.1.4)
Using erubis (2.7.0)
Using rack (1.5.2)
Using rack-test (0.6.2)
Using actionpack (4.0.0.rc2)
Using mime-types (1.23)
Using polyglot (0.3.3)
Using treetop (1.4.14)
Using mail (2.5.4)
Using actionmailer (4.0.0.rc2)
Using activemodel (4.0.0.rc2)
Using activerecord-deprecated_finders (1.0.3)
Using arel (4.0.0)
Using activerecord (4.0.0.rc2)
Using coffee-script-source (1.6.2)
Using execjs (1.4.0)
Using coffee-script (2.2.0)
Using thor (0.18.1)
Using railties (4.0.0.rc2)
Using coffee-rails (4.0.0)
Using hike (1.2.3)
Using jbuilder (1.4.2)
Using jquery-rails (3.0.1)
Using json (1.8.0)
Using bundler (1.3.5)
Using tilt (1.4.1)
Using sprockets (2.10.0)
Using sprockets-rails (2.0.0)
Using rails (4.0.0.rc2)
Using rdoc (3.12.2)
Using sass (3.2.9)
Using sass-rails (4.0.0.rc2)
Using sdoc (0.3.20)
Using turbolinks (1.2.0)
Using uglifier (2.1.1)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

gemfile.lock:

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (4.0.0.rc2)
      actionpack (= 4.0.0.rc2)
      mail (~> 2.5.3)
    actionpack (4.0.0.rc2)
      activesupport (= 4.0.0.rc2)
      builder (~> 3.1.0)
      erubis (~> 2.7.0)
      rack (~> 1.5.2)
      rack-test (~> 0.6.2)
    activemodel (4.0.0.rc2)
      activesupport (= 4.0.0.rc2)
      builder (~> 3.1.0)
    activerecord (4.0.0.rc2)
      activemodel (= 4.0.0.rc2)
      activerecord-deprecated_finders (~> 1.0.2)
      activesupport (= 4.0.0.rc2)
      arel (~> 4.0.0)
    activerecord-deprecated_finders (1.0.3)
    activesupport (4.0.0.rc2)
      i18n (~> 0.6, >= 0.6.4)
      minitest (~> 4.2)
      multi_json (~> 1.3)
      thread_safe (~> 0.1)
      tzinfo (~> 0.3.37)
    arel (4.0.0)
    atomic (1.1.9)
    builder (3.1.4)
    coffee-rails (4.0.0)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0.beta, < 5.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.6.2)
    erubis (2.7.0)
    execjs (1.4.0)
      multi_json (~> 1.0)
    hike (1.2.3)
    i18n (0.6.4)
    jbuilder (1.4.2)
      activesupport (>= 3.0.0)
      multi_json (>= 1.2.0)
    jquery-rails (3.0.1)
      railties (>= 3.0, < 5.0)
      thor (>= 0.14, < 2.0)
    json (1.8.0)
    mail (2.5.4)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    mime-types (1.23)
    minitest (4.7.4)
    multi_json (1.7.7)
    pg (0.15.1-x86-mingw32)
    polyglot (0.3.3)
    rack (1.5.2)
    rack-test (0.6.2)
      rack (>= 1.0)
    rails (4.0.0.rc2)
      actionmailer (= 4.0.0.rc2)
      actionpack (= 4.0.0.rc2)
      activerecord (= 4.0.0.rc2)
      activesupport (= 4.0.0.rc2)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.0.0.rc2)
      sprockets-rails (~> 2.0.0)
    railties (4.0.0.rc2)
      actionpack (= 4.0.0.rc2)
      activesupport (= 4.0.0.rc2)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (10.1.0)
    rdoc (3.12.2)
      json (~> 1.4)
    sass (3.2.9)
    sass-rails (4.0.0.rc2)
      railties (>= 4.0.0.beta, < 5.0)
      sass (>= 3.1.10)
      sprockets-rails (~> 2.0.0)
    sdoc (0.3.20)
      json (>= 1.1.3)
      rdoc (~> 3.10)
    sprockets (2.10.0)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sprockets-rails (2.0.0)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      sprockets (~> 2.8)
    thor (0.18.1)
    thread_safe (0.1.0)
      atomic
    tilt (1.4.1)
    treetop (1.4.14)
      polyglot
      polyglot (>= 0.3.1)
    turbolinks (1.2.0)
      coffee-rails
    tzinfo (0.3.37)
    uglifier (2.1.1)
      execjs (>= 0.3.0)
      multi_json (~> 1.0, >= 1.0.2)

PLATFORMS
  x86-mingw32

DEPENDENCIES
  coffee-rails (~> 4.0.0)
  jbuilder (~> 1.2)
  jquery-rails
  pg (= 0.15.1)
  rails (= 4.0.0.rc2)
  sass-rails (~> 4.0.0.rc2)
  sdoc
  turbolinks
  uglifier (>= 1.3.0)

pgAdminIII 已启动并运行:

错误页面:

【问题讨论】:

    标签: gem installation ruby-on-rails-4 postgresql-9.2


    【解决方案1】:

    您的宝石列表显示:

    pg (0.15.1 x64-mingw32)

    但您的 Gemfile.lock 显示

    平台 x86-mingw32

    我认为您的问题与混合平台(32 位(x86)与 64 位(x64))有关

    尝试对此进行调查。

    【讨论】:

    • 好点!谢谢。你能告诉我如何强制捆绑安装 x64 位版本 gem 吗?我是一个愚蠢的新手。 x64 pg gem 已经在 gem 列表中。
    • 我认为你应该安装 MinGW 64 位:qt-project.org/wiki/MinGW-64-bit,然后删除 Gemfile.lock,然后再次运行 bundle install。但我不太确定。
    • 您也可以尝试使用以下命令安装 pg gem:gem install pg --platform=mswin32
    • 在卸载 Ruby 64 位并安装 Ruby 32 位后,它开始工作了。不知道为什么 64 位不工作。
    • 刚刚遇到了同样的问题,让我失去了理智,感谢您发表如此详尽的帖子并最终在此处提供答案。我做了同样的事情,它奏效了。再次感谢。
    【解决方案2】:

    你是如何运行服务器的? 试试 bundle exec rails s

    【讨论】:

    • 首先,非常感谢您的建议。我已经等了一整天了。终于有好人回复了。我刚刚尝试了 bundle exec rails 。相同的错误页面。
    • 我在已安装 gem 的列表中看不到 pg(您粘贴的 bundle 命令的输出)。但我在 gemfile.lock 中看到了它。很奇怪。再来一次“捆绑安装”怎么样?
    • 感谢@pedz 的建议。是的,我试过了。仍然是相同的错误页面。
    • 也许尝试将捆绑器添加到标签列表中?对我来说,这看起来像是一个打包问题......我很难过。对不起。
    • 另一个建议。 do: bundle exec gem list 并查看列表是否包含 pg。我敢打赌它不会。 bundle 命令的执行方式有些奇怪。
    猜你喜欢
    • 2021-08-18
    • 2013-01-13
    • 1970-01-01
    • 2014-08-29
    • 2013-09-10
    • 2017-06-15
    • 1970-01-01
    • 2017-03-19
    • 2013-12-16
    相关资源
    最近更新 更多