Cannot load 'pry' - `require': cannot load such file -- pry (LoadError)

11,464

I was receiving a similar error trying to run my gem cars:

/Users/giovanni/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- pry (LoadError)
    from /Users/giovanni/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/giovanni/.rvm/gems/ruby-2.2.3/gems/cars-0.0.6/bin/cars:3:in `<top (required)>'
    from /Users/giovanni/.rvm/gems/ruby-2.2.3/bin/cars:23:in `load'
    from /Users/giovanni/.rvm/gems/ruby-2.2.3/bin/cars:23:in `<main>'
    from /Users/giovanni/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `eval'
    from /Users/giovanni/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `<main>'

I deducted that maybe my gem was not installed so I just ran:

➜  ~ gem install pry
Fetching: coderay-1.1.2.gem (100%)
Successfully installed coderay-1.1.2
Fetching: method_source-0.9.0.gem (100%)
Successfully installed method_source-0.9.0
Fetching: pry-0.11.3.gem (100%)
Successfully installed pry-0.11.3
3 gems installed

And then executed my gem as usual

Share:
11,464
gangelo
Author by

gangelo

Updated on June 24, 2022

Comments

  • gangelo
    gangelo almost 2 years

    I'm trying to debug a simple ruby console script and am getting a load error when trying to require pry:

    • I'm using rbenv to management environment.
    • I'm using Ruby version: 2.3.1.
    • Trying to use Pry '~> 0.10.4'

    /Users/gangelo/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- pry (LoadError)

    I've used Pry and Byebug in the past in rails applications and never had any issues like this. Searching for a solution, I've found that most issues are related to either not including Pry in the Gemfile or not including the Pry gem in the correct environment in the Gem file; this isn't the case with me, what am I doing wrong?

    # /Gemfile
    group :development, :test do
      gem 'pry', '~> 0.10.4'
    end
    

    And in my script:

    # /calculator/rpn_calculator_service.rb
    module RealPage
      module Calculator
        # Provides Reverse Polish Notation computation services.
        class RPNCalculatorService < CalculatorService
          include Helpers::Arrays
    
          def initialize
            super RPNInputParser.new
          end
    
          def compute(input)
            # Load error here :(
            require 'pry'; binding.pry
            # Code removed for brevity...
          end
          # Code removed for brevity...
        end
      end
    end