Calysto / xonsh_kernel

Jupyter Kernel for Xonsh
22 stars 2 forks source link

Not attaching to xonsh installation #2

Closed lmmx closed 8 years ago

lmmx commented 8 years ago

I installed with pip install xonsh_kernel on IPython 4.0, Python 3.5 (Anaconda on Linux Mint)

pip show xonsh-kernel says it's installed:


---
Metadata-Version: 2.0
Name: xonsh-kernel
Version: 0.1.0
Summary: An Xonsh kernel for Jupyter/IPython
Home-page: https://github.com/calysto/xonsh_kernel
Author: Steven Silvester
Author-email: steven.silvester@ieee.org
License: MIT
Location: /home/louis/anaconda3/lib/python3.5/site-packages
Requires: metakernel, IPython

But no entry in ~/.local/share/jupyter/kernels (where matlab_kernel went for example) nor in ~/.ipython/kernels nor in /usr/local/share/jupyter/kernels, and so no entry in the 'select kernel' menu item, and "No such kernel error" when I run ipython qtconsole --kernel=xonsh_kernel

Traceback (most recent call last):
  File "/home/louis/anaconda3/lib/python3.5/site-packages/jupyter_client/kernelspec.py", line 141, in get_kernel_spec
    resource_dir = d[kernel_name.lower()]
KeyError: 'xonsh_kernel'

During handling of the above exception, another exception occurred:

...

  File "/home/louis/anaconda3/lib/python3.5/site-packages/jupyter_client/kernelspec.py", line 143, in get_kernel_spec
    raise NoSuchKernel(kernel_name)
jupyter_client.kernelspec.NoSuchKernel: 'xonsh_kernel'

Have I missed something obvious here or is this a work in progress..? Or perhaps not compatible with IPython 4 yet ?

blink1073 commented 8 years ago

Hmm, it should work with IPython 4, is it listed under $ jupyter-kernelspec list? If not, perhaps something went wrong during the install. You could nuke it from pip and pip install again and paste the full output.

lmmx commented 8 years ago

No it isn't... pip 7.1.2 via .../anaconda3/lib/python3.5/site-packages (python 3.5)

Collecting xonsh-kernel
  Getting page https://pypi.python.org/simple/xonsh-kernel/
  Starting new HTTPS connection (1): pypi.python.org
  "GET /simple/xonsh-kernel/ HTTP/1.1" 200 253
  1 location(s) to search for versions of xonsh-kernel:
  * https://pypi.python.org/simple/xonsh-kernel/
  Getting page https://pypi.python.org/simple/xonsh-kernel/
  Analyzing links from page https://pypi.python.org/simple/xonsh-kernel/
    Found link https://pypi.python.org/packages/source/x/xonsh_kernel/xonsh_kernel-0.1.0.tar.gz#md5=d06811052fa6669481c288d74413096c (from https://pypi.python.org/simple/xonsh-kernel/), version: 0.1.0
    Found link https://pypi.python.org/packages/source/x/xonsh_kernel/xonsh_kernel-0.1.0.zip#md5=7586e65b54c33f85c24b11483a975c35 (from https://pypi.python.org/simple/xonsh-kernel/), version: 0.1.0
  Using version 0.1.0 (newest of versions: 0.1.0, 0.1.0)
  Using cached wheel link: file:///home/louis/.cache/pip/wheels/eb/71/0e/003a5580cdbb259610300f19bd59d168ff6245eed2a3b450ae/xonsh_kernel-0.1.0-py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): metakernel>=0.9 in ./anaconda3/lib/python3.5/site-packages (from xonsh-kernel)
Requirement already satisfied (use --upgrade to upgrade): IPython>=3.0 in ./anaconda3/lib/python3.5/site-packages (from xonsh-kernel)
Installing collected packages: xonsh-kernel

Successfully installed xonsh-kernel-0.1.0
Cleaning up...
Available kernels:
  igo              /home/louis/.ipython/kernels/igo
  python3          /home/louis/anaconda3/lib/python3.5/site-packages/ipykernel/resources
  ir               /home/louis/.local/share/jupyter/kernels/ir
  julia 0.3        /home/louis/.local/share/jupyter/kernels/julia 0.3
  julia-0.4        /home/louis/.local/share/jupyter/kernels/julia-0.4
  matlab_kernel    /home/louis/.local/share/jupyter/kernels/matlab_kernel
  python2          /home/louis/.local/share/jupyter/kernels/python2
scopatz commented 8 years ago

What version of xonsh are you on?

blink1073 commented 8 years ago

I just released a new version, please try pip install -U xonsh_kernel.

lmmx commented 8 years ago

Awfully sorry guys - I figured out it was due to the xonsh program at /usr/bin/xonsh being hardcoded in the shebang line to #!/usr/bin/python3 -u which is python3.4 (not Conda) whereas the actual python command on my system (i.e. #!/usr/bin/env python -u) points to python3.5 (via Anaconda3).

I installed xonsh prior to setting up the Conda environment, so it was on the system python3 only, not Conda environment python(3), which Jupyter notebook accesses.

#!/usr/bin/python3 -u
from xonsh.main import main
main()

─────────────────────────────────────────────────────────────────────────
louis ~ $ /usr/bin/python -u                                                                                                         
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
>>> 
louis ~ $ /usr/bin/python3 -u
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
>>> 
louis ~ $ python3 -u                                                                                                                 
Python 3.5.0 |Anaconda 2.4.0 (64-bit)| (default, Oct 19 2015, 21:57:25) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
>>> 

I ran pip install xonsh (i.e. for Conda python3 pip3), and then installed the updated xonsh_kernel and it now shows up in the kernels (hurrah!)

... the bad news is there are now 2, one seemingly installed via pip install xonsh and one via pip install xonsh_kernel (distinguished from the HTML id attributes of the menu items, as both are labelled "Xonsh")

[W 18:14:17.463 NotebookApp] Timeout waiting for kernel_info reply from 1573119f-e406-4023-9784-8b2941cdb29a

Sorry if I've gone about this the wrong way.


I was getting

/usr/bin/env: python -u: No such file or directory

so I rewrote the xonsh executable file as noted in this xonsh thread as:

#!/usr/bin/env sh
export PYTHONUNBUFFERED="XONSH_SET"
/usr/bin/env python -c "from xonsh.main import main; main()"

and solved this issue. The kernel still doesn't work though so I'll leave the logs above in case they help debug the issue.

blink1073 commented 8 years ago

Does it work if you: export PYTHONUNBUFFERED="XONSH_SET"; jupyter notebook?

lmmx commented 8 years ago

@blink1073: No change there unfortunately

blink1073 commented 8 years ago

Bummer, I'm afraid I'm out of ideas on this one.

IanSudbery commented 8 years ago

I get the same as @lmmx, both with using xonsh and xonsh_kernel as the kernel.

scopatz commented 8 years ago

There is more discussion of the fix at scopatz/xonsh#565, which I think just needs to be cleaned up to provide a xonsh.sh script.

IanSudbery commented 8 years ago

Cheers, I still get this problem even with PYTHONUNBUFFERED set - I get no response from the "xonsh" kernel, while the "xonsh_kernel" kernel gives me the error in the TypeError referenced in the first post.

An interesting thing to note is that when when I use the "xonsh" kernel, i while I get very high CPU usage: effectively one CPU fully utilised. When I look at whats using it, it is a bash process, running a scrip that I think is created by foreign_shells.py, at least it starts:

 bash -i -c echo __XONSH_ENV_BEG__?env?echo __XONSH_ENV_END__?echo __XONSH_ALIAS_BEG__?alias?echo __XONSH_ALIAS_END__?echo __XONSH_FUNCS_BEG__?# get function names from declare?declstr=$(declare -F)?read -r -a

When I kill jupyter, this continues to run, one of these had been running for 18 hours before I caught it. Oh, and they need kill -9 to get rid of them.

scopatz commented 8 years ago

Hi @IanSudbery, Ok can you try a couple of things then please? The first is to see if we can get this to stop by not loading bash. Set the foreign shells section of your config file (~/.local/config/xonsh/config.json) to empty:

{"foreign_shells": []}

Does the high-cpu Bash process still get spawned? The second thing to try is to turn off the safety and have bash throw an exception. For this, set you config file to:

{"foreign_shells": [
    {"shell": "bash", "safe": false}
 ]
}

Does this throw an error, and if so, what?

Note that these can be separate files that you pass in at the command line via xonsh --config-path <file>.

IanSudbery commented 8 years ago

Hi @scopatz,

Thanks for your help. If I set foriegn_shells to empty, then I don't get the high CPU Bash process. The kernel sort of works...

In python mode, I can type python and get responses. However, in subprocess mode, the output goes to the terminal I started jupyter from rather than to the notebook. At this point, I have lost control of the terminal ^C, ^Z do nothing and I have to kill the juptyer process from elsewhere.

If I set bash to unsafe, I get the same as before ... no response at all from the kernel and a high-cpu Bash process.

scopatz commented 8 years ago

@IanSudbery - OK, some progress at least. What version of jupyter are you using?

IanSudbery commented 8 years ago

@scopatz -jupyter 4.0.6

scopatz commented 8 years ago

Hmmm OK. I am seeing this issue now too.

scopatz commented 8 years ago

This should be fixed on master xonsh now.

blink1073 commented 8 years ago

I can't verify, because I could not reproduce, I'll wait for @IanSudbery or @lmmx to chime in.

IanSudbery commented 8 years ago

Sorry, I've been away, I'll try to test this out today.

IanSudbery commented 8 years ago

Works great now from both Xonsh master and here.

blink1073 commented 8 years ago

Great, thanks, closing as fixed.