wuub / SublimeREPL

SublimeREPL - run an interpreter inside ST2 (Clojure, CoffeeScript, F#, Groovy, Haskell, Lua, MozRepl, NodeJS, Python, R, Ruby, Scala, shell or configure one yourself)
https://github.com/wuub/SublimeREPL
Other
2.14k stars 312 forks source link

Ruby REPL doesn't work #168

Open IanVaughan opened 11 years ago

IanVaughan commented 11 years ago

When I select SublimeREPL: Ruby, a new tab is opened in ST2, with the following error :

/Users/ivaughan/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find pry (>= 0) amongst [POpen4-0.1.4, Platform-0.4.0, SyslogLogger-1.4.1, SyslogLogger-1.4.0, actionmailer-3.1.11, actionmailer-3.1.3, actionpack-3.1.11, actionpack-3.1.3, activemodel-3.1.11, activemodel-3.1.3, activemodel-3.0.3, activerecord-3.1.11, activerecord-3.1.3, activerecord-3.0.3, activerecord-2.3.14, activeresource-3.1.11, activeresource-3.1.3, activesupport-3.1.11, activesupport-3.1.3, activesupport-3.1.0, activesupport-3.0.3, activesupport-2.3.14, addressable-2.3.2, addressable-2.2.8, addressable-2.2.7, addressable-2.2.6, airbrake-3.0.9, airbrake-3.0.5, airbrake-3.0.4, arel-2.2.3, arel-2.2.1, arel-2.0.10, authlogic-2.1.6, awesome_print-1.0.2, bcrypt-ruby-3.0.1, bigdecimal-1.1.0, bluecloth-2.0.9, builder-3.0.4, builder-3.0.0, builder-2.1.2, bundler-1.3.5, bundler-1.3.3, capybara-1.1.3, celluloid-0.12.4, childprocess-0.3.6, cicphash-1.0.0, coffee-rails-3.1.1, coffee-script-2.2.0, coffee-script-source-1.1.3, colored-1.2, columnize-0.3.6, connection_pool-0.9.3, crack-0.3.1, crack-0.1.6, cucumber-1.2.1, cucumber-rails-1.2.1, daemons-1.1.9, daemons-1.1.4, dalli-1.1.5, dalli-1.1.4, dalli-ext-spymemcached-1.0.2, data_mapper-1.2.0, data_objects-0.10.12, date_validator-0.6.2, debugger-1.5.0, debugger-linecache-1.2.0, debugger-ruby_core_source-1.2.0, dedent-0.0.2, diff-lcs-1.2.1, diff-lcs-1.1.3, dm-aggregates-1.2.0, dm-constraints-1.2.0, dm-core-1.2.0, dm-do-adapter-1.2.0, dm-migrations-1.2.0, dm-postgres-adapter-1.2.0, dm-serializer-1.2.2, dm-timestamps-1.2.0, dm-transactions-1.2.0, dm-types-1.2.2, dm-validations-1.2.0, do_postgres-0.10.12, domain_name-0.5.3, email_veracity-0.6.0, erubis-2.7.0, eventmachine-1.0.0, eventmachine-0.12.10, execjs-1.2.12, facter-1.6.16, factory_girl-2.6.4, fakeweb-1.3.0, fakeweb-1.2.8, faraday-0.7.6, fastercsv-1.5.5, ffi-1.1.5, foreman-0.62.0, geoip-c-0.8.0, gherkin-2.11.5, gherkin-2.11.1, gisty-0.2.3, git-1.2.5, git-up-0.5.8, gmail-0.4.0, gmail_xoauth-0.3.2, going_postal-0.1.0, grit-2.5.0, haml-3.1.4, haml-3.1.3, hashie-0.2.0, highline-1.6.16, hike-1.2.1, hoe-2.12.4, hpricot-0.8.2, http_tools-0.4.4, httparty-0.9.0, httparty-0.8.3, httparty-0.5.2, i18n-0.6.4, i18n-0.6.1, i18n-0.6.0, io-console-0.3, jeweler-1.8.4, jeweler-1.5.0.pre3, jquery-rails-1.0.19, json-1.7.7, json-1.7.4, json-1.6.3, json-1.5.4, json-1.4.6, json-1.4.3, json_pure-1.7.7, kgio-2.7.4, launch-2.0.0, launch_tracks-0.1.0, launchy-2.0.5, libv8-3.3.10.4-x86_64-darwin-11, libwebsocket-0.1.5, mail-2.4.4, mail-2.3.3, mail-2.3.0, mechanize-2.5.1, memcache-1.2.12, memcaches_page-0.1.2, metaclass-0.0.1, mime-0.1, mime-types-1.21, mime-types-1.19, mime-types-1.17.2, minitest-2.5.1, mocha-0.12.4, mocha-0.9.9, mocha-0.9.8, multi_json-1.7.3, multi_json-1.5.1, multi_json-1.3.5, multi_json-1.0.4, multi_json-1.0.3, multi_xml-0.5.3, multi_xml-0.5.2, multi_xml-0.5.1, multipart-post-1.1.5, mygit-0.0.11, mysql-2.8.1, mysql2-0.3.11, mysql2-0.3.10, mysql2-0.3.7, net-http-digest_auth-1.2.1, net-http-persistent-2.8, net-http-persistent-2.7, net-http-pipeline-1.0.1, net-scp-1.0.4, net-ssh-2.6.2, newrelic-sequel-0.0.5, newrelic_rpm-3.5.8.72, newrelic_rpm-3.5.3.25, nokogiri-1.5.5, nokogiri-1.5.0, ntlm-http-0.1.1, oauth-0.4.6, open4-1.3.0, pg-0.15.1, pg-0.14.1, polyglot-0.3.3, posix-spawn-0.3.6, rabl-0.2.8, rack-1.5.2, rack-1.4.1, rack-1.3.10, rack-1.3.5, rack-cache-1.2, rack-cache-1.1, rack-contrib-1.1.0, rack-idle-0.1.0, rack-mount-0.8.3, rack-protection-1.2.0, rack-protection-1.1.4, rack-revision-info-0.4.1, rack-ssl-1.3.3, rack-ssl-1.3.2, rack-static_fallback-1.0.4, rack-test-0.6.2, rack-test-0.6.1, rails-3.1.11, rails-3.1.3, railties-3.1.11, railties-3.1.3, raindrops-0.10.0, rake-10.0.3, rake-0.9.2.2, rake-0.8.7, rbtree-0.3.0, rcov-0.9.9, rdoc-4.0.0, rdoc-3.12.1, rdoc-3.11, rdoc-3.9.4, rdoc-2.5.11, redgreen-1.2.2, redis-3.0.2, redis-namespace-1.2.1, reek-1.2.8, rspec-2.11.0, rspec-2.10.0, rspec-2.8.0, rspec-2.7.0, rspec-core-2.11.1, rspec-core-2.10.1, rspec-core-2.8.0, rspec-core-2.7.1, rspec-expectations-2.11.2, rspec-expectations-2.10.0, rspec-expectations-2.8.0, rspec-expectations-2.7.0, rspec-mocks-2.11.1, rspec-mocks-2.10.1, rspec-mocks-2.8.0, rspec-mocks-2.7.0, rspec-rails-2.8.1, rspec-rails-2.7.0, ruby-prof-0.9.2, ruby2ruby-1.2.5, ruby_parser-2.0.5, rubycas-client-2.2.1, rubyzip-0.9.9, sass-3.1.11, sass-rails-3.1.5, selenium-webdriver-2.26.0, sequel-3.45.0, sequel-3.42.0, sequel-3.39.0, sequel-3.29.0, sexp_processor-3.0.5, shotgun-0.9, shoulda-matchers-1.0.0, sidekiq-2.6.0, simplecov-0.6.1, simplecov-0.5.4, simplecov-html-0.5.3, sinatra-1.3.2, sinatra-1.3.1, sphinx-0.9.9.2117, sprockets-2.0.4, sprockets-2.0.3, sqlite3-1.3.4, statsd-ruby-1.0.0, stringex-1.5.1, therubyracer-0.9.9, thin-1.5.0, thin-1.3.1, thor-0.14.6, tickspot-0.1.0, tilt-1.3.3, timecop-0.3.5, timers-1.0.2, tracks-0.2.0, tracks-0.1.0, treetop-1.4.12, treetop-1.4.10, trollop-2.0, tzinfo-0.3.36, tzinfo-0.3.35, tzinfo-0.3.31, uglifier-1.0.4, unf-0.0.5, unf_ext-0.0.5, unicorn-4.4.0, uuidtools-2.1.4, uuidtools-2.1.2, warden-1.0.6, webmock-1.8.7, webmock-1.8.3, webmock-1.7.10, webrat-0.7.3, webrobots-0.0.13, will_paginate-3.0.2, xpath-0.1.4, yajl-ruby-1.1.0, yajl-ruby-0.8.3, yard-0.6.3] (Gem::LoadError)
    from /Users/ivaughan/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
    from /Users/ivaughan/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rubygems.rb:1231:in `gem'
    from /Users/ivaughan/Library/Application Support/Sublime Text 2/Packages/SublimeREPL/config/Ruby/pry_repl.rb:2:in `<main>'

***Repl Closed***

My env is

RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.25
  - RUBY VERSION: 1.9.3 (2012-11-10 patchlevel 327) [x86_64-darwin11.4.2]
  - INSTALLATION DIRECTORY: /Users/ivaughan/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /Users/ivaughan/.rbenv/versions/1.9.3-p327/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/ivaughan/.rbenv/versions/1.9.3-p327/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-11
  - GEM PATHS:
     - /Users/ivaughan/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1
     - /Users/ivaughan/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "install" => "--no-rdoc --no-ri"
     - "update" => "--no-rdoc --no-ri"
  - REMOTE SOURCES:
     - http://rubygems.org/

I just so happen to have pry installed.

$ gem list | grep pry
pry (0.9.12.2)

ST2.0.1, Build 2217. Was restarted after SublimeREPL was installed, via the Package Control.

wuub commented 11 years ago

There is no pry in the gem list under SublimeREPL. I'm pretty sure it's some kind of .rbenv confision and/or GEM PATHS problems.

Try playing with: SublimeREPL/config/Ruby/pry_repl.rb. Print your environment variables at the beginning, run it through SublimeREPL and then from terminal. See what's different. There is 99% chance that something will stand out.

If it'll be some kind of env var like I expect, you can put it in { "default_extend_env": {"PATH": "{PATH}:..."}, }

in Preferences -> Packages Settings -> SublimeREPL -> User

IanVaughan commented 11 years ago

Cheers for your help and reply.

I tracked it down via checking ENV within pry_repl.rb as you suggested. It seems the env is not set correctly.

"RBENV_VERSION"=>"1.9.3-p194"
"PATH"=>"/Users/ivaughan/.rbenv/versions/1.9.3-p194/bin:/Users/ivaughan/.rbenv/libexec:/Users/ivaughan/.rbenv/plugins/ruby-build/bin:/Users/ivaughan/.rbenv/shims:/Users/ivaughan/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/X11/bin:/Users/ivaughan/bin:/usr/local/sbin:/usr/local/bin"

Notice the ruby version, it's p194 in the REPL ENV, but in my shell, I am using p327.

So, as you suggested, I overrode default_extend_env within SublimeREPL.sublime-settings (the user one), and although setting the PATH worked, I had to ensure the correct path was first :

{
  "default_extend_env": {"PATH": "/Users/ivaughan/.rbenv/versions/1.9.3-p327/bin:{PATH}"}
}

I then played further, and found that setting the RBENV_VERSION worked even better :

{
  "default_extend_env": {"RBENV_VERSION": "1.9.3-p327"}
}

This meant the ENV within the pry_repl.rb was fully setup correctly :

"RBENV_VERSION"=>"1.9.3-p327"
"PATH"=>"/Users/ivaughan/.rbenv/versions/1.9.3-p327/bin:/Users/ivaughan/.rbenv/libexec:/Users/ivaughan/.rbenv/plugins/ruby-build/bin:/Users/ivaughan/.rbenv/shims:/Users/ivaughan/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/X11/bin:/Users/ivaughan/bin:/usr/local/sbin"

Once this was set once, it could be removed, and it it persisted all my ST2 sessions, even when it was restarted.

This is a great work around, but as you might suspect, when the ruby version changes in the shell, the ENV within Pry is still at p327, so it would be nice if that env could follow the shell version. I don't know how to get that working myself, so I hope this ticket can remain open as a guide to a work around and a issue to be fixed?

wuub commented 11 years ago

Great, thank you for writing it down, It will definitely help someone in the future.

Regarding OOTB functionality. Getting correct environment variables is a long standing problem in SublimeREPL (and Sublime Text in general) or at least I've not seen a working workaround yet.
We've been able to get along just fine with default_extend_env hack for now, but I think with rbenv and planned work with Django and Rails I will have to revisit this subject and try to hack something together.

Maybe even throw virtualenvwrapper and activation scripts into the mix. We will see, it' not something that I'm willing to ignore much longer.

Once again, thank you for your help and following up! :+1:

yangchenyun commented 11 years ago

I encountered the same issue. Just setup the RBENV_VERSION doesn't solve the issue, setup the PATH for ruby works for me.

gpherguson commented 11 years ago

I added the following to my User's settings for SublimeREPL:

{
  // default_extend_env are used to augment any environment variables
  // that should be visible for all subprocess repls launched within
  // SublimeREPL. This is a very good place to add PATH extension
  // once "PATH": "{PATH}:/home/username/mylocalinstalls/bin" or whatever
  "default_extend_env": {
    "PATH": "{HOME}/.rbenv/shims/:/usr/local/bin:{PATH}"
  }
}

Which seems to have fixed the problem in both ST2 and ST3.

rochet commented 11 years ago

If anyone is using rvm then you need this instead.

{ 
// default_extend_env are used to augment any environment variables
// that should be visible for all subprocess repls launched within
// SublimeREPL. This is a very good place to add PATH extension
// once "PATH": "{PATH}:/home/username/mylocalinstalls/bin" or whatever
    "default_extend_env": {
    "PATH": "{HOME}/.rvm/bin/:/usr/local/bin/:{PATH}"
      }
}
mwsage commented 11 years ago

@rochet could you please explain what exactly I would do to edit your posting to work on my system, ie. I don't know what to substitute out for any specific directories to match my settings. I know this question is not advanced but I am just learning and this REPL will seem to speed the process up from creating files in ST2 and running them through terminal. Thanks!

joenguyen commented 10 years ago

@rochet Thanks. This is exactly what I needed.

wldcordeiro commented 10 years ago

Would anyone happen to have fixed this issue on Windows? I'm not sure what to set the config to.

nolanbconaway commented 10 years ago

I'm having an identical issue, but my attempts to implement the above solutions have not worked. I'm not a ruby expert and i'm not an REPL expert, so forgive me if i made a dumb mistake.

I'm running sublime text 3 build 3062 on OSX, i install ruby through rvm and REPL through package control. Heres my ruby environment when i run it through my terminal:

nolanconaway@NBC-MBP: ~ >> gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.2.2
  - RUBY VERSION: 2.1.2 (2014-05-08 patchlevel 95) [x86_64-darwin13.0]
  - INSTALLATION DIRECTORY: /Users/nolanconaway/.rvm/gems/ruby-2.1.2
  - RUBY EXECUTABLE: /Users/nolanconaway/.rvm/rubies/ruby-2.1.2/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/nolanconaway/.rvm/gems/ruby-2.1.2/bin
  - SPEC CACHE DIRECTORY: /Users/nolanconaway/.gem/specs
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-13
  - GEM PATHS:
     - /Users/nolanconaway/.rvm/gems/ruby-2.1.2
     - /Users/nolanconaway/.rvm/gems/ruby-2.1.2@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/nolanconaway/.rvm/gems/ruby-2.1.2/bin
     - /Users/nolanconaway/.rvm/gems/ruby-2.1.2@global/bin
     - /Users/nolanconaway/.rvm/rubies/ruby-2.1.2/bin
     - /Library/Frameworks/Python.framework/Versions/2.7/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /usr/local/bin
     - /opt/X11/bin
     - /Users/nolanconaway/.rvm/bin

and

nolanconaway@NBC-MBP: ~ >> which ruby
/Users/nolanconaway/.rvm/rubies/ruby-2.1.2/bin/ruby

Given earlier posts in this thread, i added my local install directory to default_extend_env. So now the beginning of SublimeREPL.sublime-settings looks like:

{
    "default_extend_env": {
        "PATH" : "{HOME}/.rvm/gems/ruby-2.1.2/bin:{PATH}"
      },
....

I'm not certain that i used the correct directory, so i also tried using a number of the other directories that gem env spat out, as well as copied the code posted by @rochet . In each case, i get the same error, posted at the top of this thread.

Can someone point me in the right direction? i would love for this to work.

mmahalwy commented 10 years ago

Yeah I cannot get this to work either!

shenchao890216 commented 9 years ago

I cannot get this to work.I really want to know why?

fascox commented 9 years ago

same here, doesn't work with : { "default_extend_env": {"PATH": "{HOME}/.rbenv/bin:{HOME}/.rbenv/shims:{PATH}" } } pick wrong ruby version

collinksmith commented 9 years ago

When I had this problem, updating the PATH as described above successfully changed the ruby version the REPL was trying to use, but didn't fix the error message. To fix the error, I also had to update the GEM_PATH with the gem path I found by running "gem env" at the command line. For me, the whole thing looks like this: { "default_extend_env": { "PATH": "{HOME}/.rvm/rubies/ruby-2.2.0/bin:{PATH}", }, "default_extend_env": { "GEM_PATH": "{HOME}/.rvm/rubies/ruby-2.2.0/bin:/usr/local/bin/:{PATH}", }

I'll note that this got rid of the "could not find pry" error, but led to a new error: "uninitialized constant Pry::InputCompleter (NameError)." To solve that, I followed the instructions here (it's just changing a few lines in SublimeREPL's ruby config file).

After that last change, the changes I made to PATH and GEM_PATH turned out to be unnecessary. At any rate, that worked for me and hopefully it will help someone in the future.

pjhayward commented 9 years ago

I took what @collinksmith said (including the pull request) and got it to work with a few changes. I had to change the SublimeREPL.sublime-settings file like this:

{
    "default_extend_env": 
    {
        "PATH": "{HOME}/.rvm/rubies/ruby-2.1.5:{PATH}",
        "GEM_PATH": "{HOME}/.rvm/gems/ruby-2.1.5:{PATH}"
    }
}

Note the gem path stating gems specifically.

Unfortunately, it seems that the code changes in that pull request breaks the transfer from the source buffer. I'm going to see what can be done with that.

davidhq commented 9 years ago

General solution for rbenv - should work without problems... small adjustment needed for rvm

default_extend_env setting didn't work for me at all, SublimeREPL was still trying to use system Ruby:

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/dependency.rb:296:in `to_specs': Could not find 'pry' (>= 0) among 12 total gem(s) (Gem::LoadError)

I read this: http://robdodson.me/hacking-the-path-variable-in-sublime-text/ and updated the script for rbenv (had to put rbenv path in front):

import os
import getpass

RBENV = getpass.getuser() + '/.rbenv/shims/'
os.environ['PATH'] = RBENV + ':' + os.environ['PATH']

Put this in ~/Library/Application Support/Sublime Text 3/Packages/User/Pathway.py

Then to solve the Pry::InputCompleter problem apply this https://github.com/wuub/SublimeREPL/pull/372/files manually to Packages/SublimeREPL/config/Ruby/pry_repl.rb (credit)