Open IanVaughan opened 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
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?
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:
I encountered the same issue. Just setup the RBENV_VERSION
doesn't solve the issue, setup the PATH for ruby works for me.
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.
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}"
}
}
@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!
@rochet Thanks. This is exactly what I needed.
Would anyone happen to have fixed this issue on Windows? I'm not sure what to set the config to.
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.
Yeah I cannot get this to work either!
I cannot get this to work.I really want to know why?
same here, doesn't work with : { "default_extend_env": {"PATH": "{HOME}/.rbenv/bin:{HOME}/.rbenv/shims:{PATH}" } } pick wrong ruby version
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.
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.
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)
When I select
SublimeREPL: Ruby
, a new tab is opened in ST2, with the following error :My env is
I just so happen to have
pry
installed.ST2.0.1, Build 2217. Was restarted after SublimeREPL was installed, via the Package Control.