jcartledge / sublime-worksheet

An inline REPL for JavaScript, PHP, Ruby & more in Sublime Text 2 and 3
MIT License
333 stars 18 forks source link

Node was not found or was not executable #25

Closed u840903 closed 11 years ago

u840903 commented 11 years ago

In Worksheet v0.7.3 on OSX 10.8.4 and ST2.0.1 thees lines of code result in an error.

Javascript:

var foo = function(bar){
    return bar;
}
foo('bar');

Console:

Traceback (most recent call last):
  File "./sublime_plugin.py", line 362, in run_
  File "./worksheet.py", line 101, in run
  File "./worksheet.py", line 19, in run
  File "./repl/repl.py", line 8, in get_repl
  File "./repl/repl.py", line 42, in __init__
  File "./repl/pexpect.py", line 432, in __init__
  File "./repl/pexpect.py", line 519, in _spawn
repl.pexpect.ExceptionPexpect: The command was not found or was not executable: node.
jcartledge commented 11 years ago

Thanks for the report. This looks like the same thing @CarettaCaretta reported at https://github.com/jcartledge/sublime-worksheet/issues/20#issuecomment-20284938.

I can't reproduce it here, so forgive me if I ask some obvious/stupid questions:

Uh - not sure what else to look for at this point. We'll work this out, but I'm going to need your help.

lpand commented 11 years ago

@jcartledge definitely which('node') returns None when _spawn is invoked, but from terminal

> python
>>> import pexpect as pex
>>> pex.which('node')
'/usr/local/bin/node'
>>>
> node -v
v0.10.0
> which node
/usr/local/bin/node

If i remember correct i used nave, nave usemain latest to install node.

Yesterday night it worked at some point, but today the problem is still there.

Thanks for your work, awesome plugin.

timonwong commented 11 years ago

@CarettaCaretta Because Sublime Text strip /usr/local/bin (at least) from PATH environment variable(/usr/local/bin seems only accessible from terminal), so pexpect cannot find it. You can change your worksheet.sublime-settings accordingly, in order to get it work:

        "JavaScript": {
            // Here we use absolute path for node
            "cmd": "/usr/local/bin/node -e \"require('repl').start('node> ')\"",
            "prompt": ["node> ", "\\.\\.+ "]
        }
lpand commented 11 years ago

@timonwong

i've checked, you're right and the solution works :satisfied:. Thank you.

jcartledge commented 11 years ago

That will work, but it would be better if you didn't have to hardcode it.

I'm not sure why, but /usr/local/bin is always in my path, no matter how I start ST - I thought maybe it made a difference if it was started from terminal rather than GUI, but not so.

I think it should be possible to append "/usr/local/bin" to os.environ["PATH"]. I'll check it out and see if it works so people don't have to hack their config to get it working.

kosii commented 11 years ago

For me /usr/local/bin is on the path if I start Sublime from the terminal with /Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl, but it's not present if Sublime is started by double-clicking on the Sublime application icon.

u840903 commented 11 years ago

Not sure if it's still of importance but I installed Node via Homebrew and it runs in the terminal.

> node -v
v0.10.12
> which node
/usr/local/bin/node

Happy to help!

jcartledge commented 11 years ago

Does anyone who has this problem want check if the path branch resolves it? Thanks.

jcartledge commented 11 years ago

I've merged my attempt at a fix for this into master but it's not in a release yet. I'm not going to close until someone can verify that it solves the problem for them.

u840903 commented 11 years ago

Path branch on OSX 10.8.4 and ST2.0.1 resolves the bug.

Javascript

var foo = function(bar){
    return bar;
}
foo('foobar');

Javascript after eval.

var foo = function(bar){
    return bar;
}
// > undefined

foo('foobar');
// > 'foobar'
jcartledge commented 11 years ago

Great, thanks. I'll try to wrap it up today.