Pry を起動する時にエラーが出たので、その対処
Bài đăng này đã không được cập nhật trong 9 năm
Pry を起動するとエラーが出るようになった
普段 Rails で開発していると、ちょっとした計算には電卓立ち上げるよりも、立ち上がりっぱなしの端末上で pry を使う、なんて人居ると思います。
僕もそっち派で、pry が立ち上がらないとちょっとした作業を効率よく捌けなくて困ってしまいます。
なので、こんな状況になって困ってしまいました。
/Users/norifumi% pry
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:14: warning: already initialized constant Pry::DEFAULT_HOOKS
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:14: warning: previous definition of DEFAULT_HOOKS was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:20: warning: already initialized constant Pry::DEFAULT_PRINT
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:20: warning: previous definition of DEFAULT_PRINT was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:29: warning: already initialized constant Pry::SIMPLE_PRINT
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:29: warning: previous definition of SIMPLE_PRINT was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:38: warning: already initialized constant Pry::CLIPPED_PRINT
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:38: warning: previous definition of CLIPPED_PRINT was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:43: warning: already initialized constant Pry::DEFAULT_EXCEPTION_HANDLER
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:43: warning: previous definition of DEFAULT_EXCEPTION_HANDLER was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:52: warning: already initialized constant Pry::DEFAULT_PROMPT_NAME
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:52: warning: previous definition of DEFAULT_PROMPT_NAME was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:55: warning: already initialized constant Pry::DEFAULT_PROMPT
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:55: warning: previous definition of DEFAULT_PROMPT was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:65: warning: already initialized constant Pry::DEFAULT_PROMPT_SAFE_OBJECTS
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:65: warning: previous definition of DEFAULT_PROMPT_SAFE_OBJECTS was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:68: warning: already initialized constant Pry::SIMPLE_PROMPT
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:68: warning: previous definition of SIMPLE_PROMPT was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:70: warning: already initialized constant Pry::NO_PROMPT
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:70: warning: previous definition of NO_PROMPT was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:72: warning: already initialized constant Pry::SHELL_PROMPT
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:72: warning: previous definition of SHELL_PROMPT was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:79: warning: already initialized constant Pry::NAV_PROMPT
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:79: warning: previous definition of NAV_PROMPT was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:94: warning: already initialized constant Pry::DEFAULT_CONTROL_D_HANDLER
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:94: warning: previous definition of DEFAULT_CONTROL_D_HANDLER was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:109: warning: already initialized constant Pry::DEFAULT_SYSTEM
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:109: warning: previous definition of DEFAULT_SYSTEM was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:117: warning: already initialized constant Pry::INITIAL_PWD
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:117: warning: previous definition of INITIAL_PWD was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry/cli.rb:6: warning: already initialized constant Pry::CLI::NoOptionsError
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry/cli.rb:6: warning: previous definition of NoOptionsError was here
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/specification.rb:2064:in `raise_if_conflicts': Unable to activate pry-byebug-1.3.2, because pry-0.10.0 conflicts with pry (~> 0.9.12) (Gem::LoadError)
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/specification.rb:1262:in `activate'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems.rb:196:in `rescue in try_activate'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems.rb:193:in `try_activate'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:132:in `rescue in require'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:144:in `require'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-byebug-1.3.2/lib/pry-byebug/cli.rb:1:in `<top (required)>'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry/plugins.rb:38:in `load_cli_options'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry/cli.rb:40:in `block in add_plugin_options'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry/cli.rb:39:in `each'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry/cli.rb:39:in `add_plugin_options'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry/cli.rb:107:in `<top (required)>'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/lib/pry.rb:150:in `<top (required)>'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/bin/pry:12:in `rescue in <top (required)>'
from /Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pry-0.10.0/bin/pry:8:in `<top (required)>'
from /Users/norifumi/.rbenv/versions/2.1.0/bin/pry:23:in `load'
from /Users/norifumi/.rbenv/versions/2.1.0/bin/pry:23:in `<main>'
解決策1 bundle exec pry
適当な Rails アプリケーション等の Gemfile
があるディレクトリで
/Users/norifumi/rails_app% bundle exec pry
とやれば動きます。さすがですね、bundler。でも、やっぱり任意のディレクトリで pry
したいです。pry
って3文字打ったら起動して欲しいです。
解決策2 pry のバージョン指定
Rails のバージョンを複数インスト-ルしているときに、新しい Rails アプリケーションを作成する時を思い出して下さい。
rails _4.1.4_ new blog
とやりますね。pry
も同じようにバージョンを指定して実行できます。エラーメッセージを見ると、
/Users/norifumi/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/specification.rb:2064:in `raise_if_conflicts': Unable to activate pry-byebug-1.3.2, because pry-0.10.0 conflicts with pry (~> 0.9.12) (Gem::LoadError)
とありました。そうです、 pry
のバージョン 0.9.12
を起動すれば良さそうです。
まずは、インストールされているバージョンを確認します。
/Users/norifumi% gem list | grep pry
pry (0.10.0, 0.9.12.6, 0.9.12.4)
pry-byebug (1.3.2)
pry-coolline (0.2.4)
pry-debugger (0.2.3, 0.2.2)
pry-doc (0.6.0)
pry-nav (0.2.3, 0.2.2)
pry-rails (0.3.2)
0.9.12.6
を使ってみましょう。
/Users/norifumi% pry _0.9.12.6_
[1] pry(main)>
やりました。お帰り、pry
。
でも大事なことを忘れています。3文字で起動できません。
Tab 補完が効く分、bundle exec pry
の方が下手したらキーストロークが少ないかもしれません。
惜しい。実に惜しい。
解決策2+ aliasでバージョン指定
やっぱり3文字 pry
と打ったら pry
を立ち上げたいです。なので、alias
を使いましょう。
Zsh だとこんな感じです。
/Users/norifumi% alias pry='pry _0.9.12.6_'
/Users/norifumi% pry
[1] pry(main)>
やりました。3文字で起動できるようになりました。今度こそ本当にお帰り、pry
。
この alias pry='pry _0.9.12.6_'
を ~/.zshrc
に書いておけば、今度こそ解決です。
All rights reserved