Ruby on rails ';在任何源中都找不到pg-0.12.2';运行rspec时

Ruby on rails ';在任何源中都找不到pg-0.12.2';运行rspec时,ruby-on-rails,postgresql,gem,pg,Ruby On Rails,Postgresql,Gem,Pg,我正在Hartl的Rails教程中构建twitter克隆应用程序。我克隆了我的gitrepo(),并将代码放在我的个人计算机上,这台计算机以前在我的工作计算机上。因此,我的开发人员环境可能与我的文件中指定的环境略有不同 我的环境: Mac OS 10.6.8 轨道3.2.13 ruby 1.9.3p392(2013-02-22修订版39386)[x86_64-darwin10.8.0] *本地宝石* actionmailer(3.2.13、3.2.11、3.2.1) actionpack(3.

我正在Hartl的Rails教程中构建twitter克隆应用程序。我克隆了我的gitrepo(),并将代码放在我的个人计算机上,这台计算机以前在我的工作计算机上。因此,我的开发人员环境可能与我的文件中指定的环境略有不同

我的环境: Mac OS 10.6.8 轨道3.2.13 ruby 1.9.3p392(2013-02-22修订版39386)[x86_64-darwin10.8.0]

*本地宝石*

  • actionmailer(3.2.13、3.2.11、3.2.1)
  • actionpack(3.2.13、3.2.11、3.2.1)
  • activemodel(3.2.13、3.2.11、3.2.1)
  • activerecord(3.2.13、3.2.11、3.2.1)
  • activeresource(3.2.13、3.2.11、3.2.1)
  • activesupport(3.2.13、3.2.11、3.2.1)
  • 可寻址(2.3.2)
  • 注释(2.5.0)
  • 阿雷尔(3.0.2)
  • bcrypt ruby(3.0.1)
  • bigdecimal(1.1.0)
  • 引导式sass(2.1.0.0)
  • bootstrap-will_paginate(0.0.6)
  • 建筑商(3.0.4)
  • 捆扎机(1.3.4)
  • 水豚(2.0.2,1.1.2)
  • 子进程(0.3.9,0.3.6)
  • 咖啡架(3.2.2)
  • 咖啡脚本(2.2.0)
  • coffee脚本源代码(1.6.2、1.6.1、1.4.0)
  • 黄瓜(1.2.1)
  • 黄瓜轨道(1.2.1)
  • 数据库清理器(0.7.0)
  • 差异lcs(1.2.1、1.1.3)
  • erubis(2.7.0)
  • execjs(1.4.0)
  • 工厂女孩(4.1.0)
  • 工厂女孩轨道(4.1.0)
  • 伪造者(1.0.1)
  • 外国金融机构(1.4.0、1.3.1)
  • 小黄瓜(2.11.5)
  • 徒步旅行(1.2.1)
  • i18n(0.6.1)
  • io控制台(0.3)
  • 旅程(1.0.4)
  • jquery rails(2.2.1、2.1.4、2.0.2)
  • json(1.7.7、1.7.6、1.7.5、1.5.5)
  • libwebsocket(0.1.7.1)
  • 邮件(2.5.3、2.4.4)
  • mime类型(1.21、1.19)
  • 小型试验(2.5.1)
  • multi_json(1.7.1、1.5.0)
  • 诺科吉里(1.5.8、1.5.7、1.5.6)
  • pg(0.14.1)
  • polyglot(0.3.3)
  • 机架(1.4.5、1.4.4、1.4.1)
  • 机架缓存(1.2)
  • 机架ssl(1.3.3、1.3.2)
  • 机架测试(0.6.2)
  • 轨道(3.2.13、3.2.1)
  • 栏杆(3.2.13、3.2.11、3.2.1)
  • 耙(10.0.3,0.9.2.2)
  • rdoc(3.12.2、3.12、3.9.5)
  • rspec核心(2.13.1)
  • rspec期望值(2.13.0)
  • rspec模拟(2.13.0)
  • rspec导轨(2.13.0)
  • rubygems捆扎机(1.1.1)
  • rubyzip(0.9.9)
  • rvm(1.11.3.6)
  • sass(3.2.7、3.2.4)
  • sass轨道(3.2.6、3.2.5)
  • selenium webdriver(2.31.0、2.27.2)
  • 链轮(2.2.2、2.1.3)
  • sqlite3(1.3.7)
  • 雷神(0.17.0,0.16.0,0.14.6)
  • 倾斜(1.3.6、1.3.3)
  • 树梢(1.4.12)
  • tzinfo(0.3.37,0.3.35)
  • 丑八怪(1.3.0)
  • websocket(1.0.7、1.0.6)
  • 将分页(3.0.3)
  • xpath(1.0.0,0.1.4)
我的档案:

source 'https://rubygems.org'

gem 'rails', '3.2.11'
gem 'bootstrap-sass', '2.1'
gem 'bcrypt-ruby', '3.0.1'
gem 'faker', '1.0.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'jquery-rails', '2.0.2'

group :development, :test do
  gem 'sqlite3', '1.3.5'
  gem 'rspec-rails', '2.11.0'
  # gem 'guard-rspec', '1.2.1'
  # gem 'guard-spork', '1.2.0'  
  # gem 'spork', '0.9.2'
end

group :development do
  gem 'annotate', '2.5.0'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '3.2.5'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier', '1.2.3'
end

group :test do
  gem 'capybara', '1.1.2'
  gem 'factory_girl_rails', '4.1.0'
  gem 'cucumber-rails', '1.2.1', :require => false
  gem 'database_cleaner', '0.7.0'
  # gem 'launchy', '2.1.0'
  # gem 'rb-fsevent', '0.9.1', :require => false
  # gem 'growl', '1.0.3'
end

group :production do
  gem 'pg', '0.12.2'
end
无论如何,我正试图在清单8.18()之后运行测试:

我得到了这个错误:

Could not find pg-0.12.2 in any of the sources
Run `bundle install` to install missing gems.
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Using rake (10.0.3) 
Using i18n (0.6.1) 
Using multi_json (1.5.0) 
Using activesupport (3.2.11) 
Using builder (3.0.4) 
Using activemodel (3.2.11) 
Using erubis (2.7.0) 
Using journey (1.0.4) 
Using rack (1.4.4) 
Using rack-cache (1.2) 
Using rack-test (0.6.2) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.2.2) 
Using actionpack (3.2.11) 
Using mime-types (1.19) 
Using polyglot (0.3.3) 
Using treetop (1.4.12) 
Using mail (2.4.4) 
Using actionmailer (3.2.11) 
Using arel (3.0.2) 
Using tzinfo (0.3.35) 
Using activerecord (3.2.11) 
Using activeresource (3.2.11) 
Using addressable (2.3.2) 
Using annotate (2.5.0) 
Using bcrypt-ruby (3.0.1) 
Using bootstrap-sass (2.1.0.0) 
Using will_paginate (3.0.3) 
Using bootstrap-will_paginate (0.0.6) 
Using nokogiri (1.5.6) 
Using ffi (1.3.1) 
Using childprocess (0.3.6) 
Using websocket (1.0.6) 
Using libwebsocket (0.1.7.1) 
Using rubyzip (0.9.9) 
Using selenium-webdriver (2.27.2) 
Using xpath (0.1.4) 
Using capybara (1.1.2) 
Using coffee-script-source (1.4.0) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using rack-ssl (1.3.2) 
Using json (1.7.6) 
Using rdoc (3.12) 
Using thor (0.16.0) 
Using railties (3.2.11) 
Using coffee-rails (3.2.2) 
Using diff-lcs (1.1.3) 
Using gherkin (2.11.5) 
Using cucumber (1.2.1) 
Using cucumber-rails (1.2.1) 
Using database_cleaner (0.7.0) 
Using factory_girl (4.1.0) 
Using factory_girl_rails (4.1.0) 
Using faker (1.0.1) 
Using jquery-rails (2.0.2) 
Installing pg (0.12.2) 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/stewartmccoy/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb 
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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
    --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=/Users/stewartmccoy/.rvm/rubies/ruby-1.9.3-p392/bin/ruby
    --with-pg
    --without-pg
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config


Gem files will remain installed in /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.12.2 for inspection.
Results logged to /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.12.2/ext/gem_make.out

An error occurred while installing pg (0.12.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.12.2'` succeeds before bundling.
因此,我运行
bundle install
并得到以下错误:

Could not find pg-0.12.2 in any of the sources
Run `bundle install` to install missing gems.
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Using rake (10.0.3) 
Using i18n (0.6.1) 
Using multi_json (1.5.0) 
Using activesupport (3.2.11) 
Using builder (3.0.4) 
Using activemodel (3.2.11) 
Using erubis (2.7.0) 
Using journey (1.0.4) 
Using rack (1.4.4) 
Using rack-cache (1.2) 
Using rack-test (0.6.2) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.2.2) 
Using actionpack (3.2.11) 
Using mime-types (1.19) 
Using polyglot (0.3.3) 
Using treetop (1.4.12) 
Using mail (2.4.4) 
Using actionmailer (3.2.11) 
Using arel (3.0.2) 
Using tzinfo (0.3.35) 
Using activerecord (3.2.11) 
Using activeresource (3.2.11) 
Using addressable (2.3.2) 
Using annotate (2.5.0) 
Using bcrypt-ruby (3.0.1) 
Using bootstrap-sass (2.1.0.0) 
Using will_paginate (3.0.3) 
Using bootstrap-will_paginate (0.0.6) 
Using nokogiri (1.5.6) 
Using ffi (1.3.1) 
Using childprocess (0.3.6) 
Using websocket (1.0.6) 
Using libwebsocket (0.1.7.1) 
Using rubyzip (0.9.9) 
Using selenium-webdriver (2.27.2) 
Using xpath (0.1.4) 
Using capybara (1.1.2) 
Using coffee-script-source (1.4.0) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using rack-ssl (1.3.2) 
Using json (1.7.6) 
Using rdoc (3.12) 
Using thor (0.16.0) 
Using railties (3.2.11) 
Using coffee-rails (3.2.2) 
Using diff-lcs (1.1.3) 
Using gherkin (2.11.5) 
Using cucumber (1.2.1) 
Using cucumber-rails (1.2.1) 
Using database_cleaner (0.7.0) 
Using factory_girl (4.1.0) 
Using factory_girl_rails (4.1.0) 
Using faker (1.0.1) 
Using jquery-rails (2.0.2) 
Installing pg (0.12.2) 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/stewartmccoy/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb 
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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
    --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=/Users/stewartmccoy/.rvm/rubies/ruby-1.9.3-p392/bin/ruby
    --with-pg
    --without-pg
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config


Gem files will remain installed in /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.12.2 for inspection.
Results logged to /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.12.2/ext/gem_make.out

An error occurred while installing pg (0.12.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.12.2'` succeeds before bundling.
最后,我尝试了
PATH=$PATH:/Library/PostgreSQL/9.2/bin sudo gem install pg
,得到了:

Password:
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

        /Users/stewartmccoy/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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
    --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=/Users/stewartmccoy/.rvm/rubies/ruby-1.9.3-p392/bin/ruby
    --with-pg
    --without-pg
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config


Gem files will remain installed in /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.15.0 for inspection.
Results logged to /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.15.0/ext/gem_make.out
建议


非常感谢您的帮助

您应该检查config/database.yml上有哪些适配器。您可能已经使用测试环境设置了postgres或pg适配器

但是,在Gemfile上,您仅为生产设置了postgres:

group :production do
  gem 'pg', '0.12.2'
end
如果添加测试环境并再次运行bundle,它应该可以工作:

group :test, :production do
  gem 'pg', '0.12.2'
end
另请参见以下内容中的解决方案:

尝试使用以下命令安装gem:

gem install pg -- --with-pg-config= 'PATH_TO_YOUR_PG_CONFIG'
which pg_config
如果您不知道pg_配置在哪里,请运行以下命令:

gem install pg -- --with-pg-config= 'PATH_TO_YOUR_PG_CONFIG'
which pg_config

顺便问一下,你已经在桌面上安装了postgres了吗?安装gem所需的只是postgres开发包。

ah。我刚刚检查了我的database.yml文件,所有适配器都设置为sqlite3。我需要解决这个问题。奇怪的是,我以为我已经将生产设置为postgres.btw了,我只是再次检查了你的答案,你在安装postgres时遇到了问题,你能告诉我你的操作系统吗?我更新了Gemfile:
group:test,:production do gem'pg',“0.12.2”结束
和database.yml:
生产:适配器:postgresql数据库:rails\u教程池:5超时:5000
但仍然得到:
在任何源代码中都找不到pg-0.12.2运行
捆绑安装`以安装缺少的gems。`当然。我的环境列在文章的顶部,但这里又是:Mac OS 10.6.8 Rails 3.2.13 ruby 1.9.3p392(2013-02-22修订版39386)[x86_64-darwin10.8.0]好的,你需要安装postgres,你可以用brew或port自动安装,否则你可以下载源代码,但这比使用brew要难一些。