Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jupyter #399

Merged
merged 12 commits into from Nov 7, 2015
Merged

Jupyter #399

merged 12 commits into from Nov 7, 2015

Conversation

scopatz
Copy link
Member

@scopatz scopatz commented Sep 30, 2015

Added hooks for Jupyter notebooks to be automatically installed. Now the only thing is that this won't come with the pip or conda packages unless we make the packages dependent on jupyter / ipython. Does this sound reasonable to people?

@scopatz scopatz added this to the v0.3 milestone Sep 30, 2015
@melund
Copy link
Member

melund commented Sep 30, 2015

It does. If people install Jupiter later they just have to reinstall xonsh.

This is really great. I have some unfinished attempts to implement this as well. I am glad you found the time to do it the right way. I will try it out as soon as possible :)

@melund
Copy link
Member

melund commented Sep 30, 2015

Ok. The first problem I encountered was that the kernel spec was not installed correctly when building conda packages. I have created PR to your jupyter branch that fixes this.

I haven't got the kernel to work though. It seems to start correctly even though I get this error

[I 15:34:37.924 NotebookApp] Creating new notebook in
[I 15:34:39.565 NotebookApp] Kernel started: dcf75d0c-58e6-4aea-935d-5631543d050d
[IPKernelApp] ERROR | UNKNOWN MESSAGE TYPE: 'comm_open'

But the notebook does't show any output when entering commands.

@scopatz
Copy link
Member Author

scopatz commented Sep 30, 2015

Hi @melund - Awesome :)

As per the issue that you are having, have you installed jupyter_client and/or are you on IPython v4.0+? This is what I am targeting...

@melund
Copy link
Member

melund commented Sep 30, 2015

I am using IPython 4.0, and jupyter_client is installed.. I will test again tomorrow.

"codemirror_mode":"shell",
}
if CONDA:
d = os.path.join(os.environ['PREFIX'] +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the same as sys.prefix

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. You are right. It has been a while since I tingled with these things. It is of course python in the build environment that runs setup.py, so it should be the same sys.prefix, when building.

I am not too happy about this being in the setup.py file, but I haven't seen any good ways of installing the kernel_spec with conda. You did something for the r-kernel, right? I think I saw it on conda-recipes, but I can't seem to find it now. Maybe it should be a post-install script that tests if Jupyter is there, and then runs the install_kernel_spec() function.

@asmeurer
Copy link
Contributor

asmeurer commented Oct 1, 2015

I don't think conda should have a monopoly on installing things to the install prefix, but maybe that's a more a gripe for jupyter team than xonsh.

@melund
Copy link
Member

melund commented Oct 1, 2015

It would be nice if conda could label the kernel_spec file with the environment when installing. Then we would be able to see which environment the kernel belonged to directly from the notebook.

Let's say that xonsh was installed in three environments; root, dev and test. In the notebook, it only shows one entry, of the one install last. If the conda installer could change the display_name in the kernel_spec and install it to a different folder (e.g. xonsh_dev), then I would have three entries in the notebook.

  • Xonsh
  • Xonsh (dev)
  • Xonsh (test)

Any idea how to do this @asmeurer ?

@asmeurer
Copy link
Contributor

asmeurer commented Oct 1, 2015

If you put the absolute path to the install prefix in a text file, conda will automatically replace it with the path of the install prefix (the environment). I don't know if that gets you what you want.

@melund
Copy link
Member

melund commented Oct 1, 2015

That is what we use when creating the kernel_spec. That is also the reason that I convert back-slashes to forward slashes, otherwise the prefix is not replaced. What I wanted was to also write the environment name into the file. Right now on my computer, I create the kernel specs manually, so I can access them all from the same notebook.

image

@asmeurer
Copy link
Contributor

asmeurer commented Oct 1, 2015

I thought the prefix replacement should work with backslashes. I believe you do need to use only one or the other, though (meaning use join(sys.prefix, 'share', 'jupyter', 'kernels', 'xonsh')).

@melund
Copy link
Member

melund commented Oct 1, 2015

Hmm. No. The line you are refering to is only used for to create directory in the prefix. The line where backslashes cause problems is sys.prefix in the json file.

spec = {"argv": [sys.executable, 
                         "-m", "xonsh.jupyter_kernel", 
                         "-f", "{connection_file}"],
              "display_name":"Xonsh",
              "language":"xonsh",
              "codemirror_mode":"shell" }

@asmeurer
Copy link
Contributor

asmeurer commented Oct 1, 2015

The backslashes with conda should work. If they aren't you should open an issue in the conda or conda-build issue tracker.

@scopatz
Copy link
Member Author

scopatz commented Oct 3, 2015

Is there anything that I actually need to do here?

@melund
Copy link
Member

melund commented Oct 3, 2015

Sorry. The discussion got derailed. I still can't get the kernel working. Anything else I could try?

@scopatz
Copy link
Member Author

scopatz commented Oct 3, 2015

What is the problem you are experiencing, @melund? Sorry if it isn't clear to me right now =/

  • Xonsh
  • Xonsh (dev)
  • Xonsh (test)

Any idea how to do this @asmeurer ?

That can be done by changing the label name to be based off the version.

@melund
Copy link
Member

melund commented Oct 4, 2015

With pyreadline, everything seems to work fine, but I don't see any output in the notebook. I don't really know what I could easily try.

Running it with prompt toolkit gives me a traceback from the kernel:

  File "C:\Users\mel\Documents\xonsh\xonsh\main.py", line 125, in main_context
    args = premain(argv)
  File "C:\Users\mel\Documents\xonsh\xonsh\main.py", line 72, in premain
    shell = builtins.__xonsh_shell__ = Shell(**shell_kwargs)
  File "C:\Users\mel\Documents\xonsh\xonsh\shell.py", line 40, in __init__
    ctx=self.ctx, **kwargs)
  File "C:\Users\mel\Documents\xonsh\xonsh\prompt_toolkit_shell.py", line 53, in __init__
    enable_search=True, enable_abort_and_exit_bindings=True)
TypeError: __init__() got an unexpected keyword argument 'enable_abort_and_exit_bindings'

Xonsh
Xonsh (dev)
Xonsh (test)
Any idea how to do this @asmeurer ?
That can be done by changing the label name to be based off the version.

I don't think that is the solution with conda packages. Setup.py is not run when installing a conda package. That happens only when the package is build. I think the kernel-spec files should be installed by the conda post-install scripts. We should just wait see. I am sure the conda-team will come up with a good way of doing this.

@scopatz
Copy link
Member Author

scopatz commented Oct 4, 2015

With pyreadline, everything seems to work fine,

OK. I have pushed up a temporary fix

but I don't see any output in the notebook. I don't really know what I could easily try.

I have noticed that sometimes too with respect to expressions that are evaluated. Maybe we could address this in a future PR?

Also, OK about the conda stuff.

@melund
Copy link
Member

melund commented Oct 4, 2015

Sure. If it works on Linux, the rest could be fixed in an other PR. Are there anyone else who can test on windows. I really don't know if it is only my setup...

@scopatz
Copy link
Member Author

scopatz commented Oct 5, 2015

I can see why this error is occurring, but I don't understand how @melund. I have updated the code. Can you test and see if it is giving you an AssertionError now?

@melund
Copy link
Member

melund commented Oct 5, 2015

@scopatz

Traceback (most recent call last):
  File "C:\Users\mel\Documents\xonsh\xonsh\base_shell.py", line 158, in push
    locs=self.ctx)
  File "C:\Users\mel\Documents\xonsh\xonsh\execer.py", line 95, in compile
    tree = self.parse(input, ctx, mode=mode)
  File "C:\Users\mel\Documents\xonsh\xonsh\execer.py", line 70, in parse
    tree = self._parse_ctx_free(input, mode=mode)
  File "C:\Users\mel\Documents\xonsh\xonsh\execer.py", line 151, in _parse_ctx_free
    debug_level=self.debug_level)
  File "C:\Users\mel\Documents\xonsh\xonsh\parser.py", line 264, in parse
    tree = self.parser.parse(input=s, lexer=self.lexer, debug=debug_level)
  File "C:\Users\mel\Anaconda3\envs\xonsh\lib\site-packages\ply\yacc.py", line 331, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "C:\Users\mel\Anaconda3\envs\xonsh\lib\site-packages\ply\yacc.py", line 1106, in parseopt_notrack
    p.callable(pslice)
  File "C:\Users\mel\Documents\xonsh\xonsh\parser.py", line 1627, in p_power
    assert False
AssertionError

@scopatz
Copy link
Member Author

scopatz commented Oct 5, 2015

Is this only in the notebook or on the command line too?

@melund
Copy link
Member

melund commented Oct 5, 2015

Only in the notebook. At the command line it works as I would expect.

@scopatz
Copy link
Member Author

scopatz commented Oct 5, 2015

That is super weird. I know you said that it doesn't matter what you type, but can you give me an example, please? Thanks!

@melund
Copy link
Member

melund commented Oct 5, 2015

Here is what I type at the command line to start jupyter:

[xonsh] C:\Users\mel\Documents\xonsh (jupyter)
λ jupyter notebook Untitled5.ipynb
[I 21:38:38.308 NotebookApp] Serving notebooks from local directory: C:\Users\mel\Documents\xonsh
[I 21:38:38.308 NotebookApp] 0 active kernels
[I 21:38:38.309 NotebookApp] The IPython Notebook is running at: http://localhost:8888/
[I 21:38:38.309 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[I 21:38:40.643 NotebookApp] Kernel started: 1619ae58-37f6-406d-8cc6-6a77d431af56
[IPKernelApp] ERROR | UNKNOWN MESSAGE TYPE: 'comm_open'

The UNKNOWN MESSAGE TYPE comes before I provoke the traceback.. So it may not be related.

@melund
Copy link
Member

melund commented Oct 5, 2015

Seems that import statements doesn't provoke the error. But everything else I tried does:

image

@scopatz
Copy link
Member Author

scopatz commented Oct 5, 2015

Ahh, OK. So I think that this is related. I see the same start up message that you do, but without the [IPKernelApp] ERROR | UNKNOWN MESSAGE TYPE: 'comm_open'. What version of jupyter are you using? I have

$ jupyter --version
4.0.6

Also do you have a recent version of ipykernel? The comm_open thing seems to be the correct way that the Jupyter client should act: http://jupyter-client.readthedocs.org/en/latest/messaging.html#opening-a-comm

@scopatz
Copy link
Member Author

scopatz commented Oct 5, 2015

Also, this is a very weird part of the code base to consistently be failing at...

@melund
Copy link
Member

melund commented Oct 5, 2015

I am using jupyter and notebook from continuum's anaconda repo.

[xonsh] C:\Users\mel\Documents\xonsh          
λ jupyter --version                           
4.0.6         
[xonsh] C:\Users\mel\Documents\xonsh (jupyter)
λ jupyter notebook --version
4.0.5

@melund
Copy link
Member

melund commented Oct 5, 2015

I have ipykernel version 4.0.3

@scopatz
Copy link
Member Author

scopatz commented Oct 5, 2015

hmm OK, I was on notebook, version v4.0.4. I updated to v4.0.5 and now I see [IPKernelApp] ERROR | UNKNOWN MESSAGE TYPE: 'comm_open'. However, everything seems to run just fine for me.

@scopatz
Copy link
Member Author

scopatz commented Oct 5, 2015

I am also on ipykernel v4.0.3

@scopatz
Copy link
Member Author

scopatz commented Oct 5, 2015

Ok I just opened up an issue on ipykernel

@scopatz
Copy link
Member Author

scopatz commented Oct 5, 2015

Also, what version of ply do you have?

$ python -c "import ply; print(ply.__version__)"

@scopatz
Copy link
Member Author

scopatz commented Oct 5, 2015

I am on v3.6

@melund
Copy link
Member

melund commented Oct 5, 2015

The same as you:
λ python -c "import ply; print(ply.version)"
3.6

@scopatz
Copy link
Member Author

scopatz commented Oct 5, 2015

Uggh This is nasty. Could you try sticking in a pdb or print statement into bash_shell.BaseShell.default() or .push() to figure out what line it is actually trying to execute? Thanks

@melund
Copy link
Member

melund commented Oct 5, 2015

Here I added a print('func:', line ) to both methods.
image

@scopatz
Copy link
Member Author

scopatz commented Oct 5, 2015

that makes me sad.

@melund
Copy link
Member

melund commented Oct 5, 2015

Well, I am so sorry :)

@scopatz
Copy link
Member Author

scopatz commented Oct 5, 2015

haha not your fault, of course :)

@melund
Copy link
Member

melund commented Oct 5, 2015

It is getting late here, and I am hosting a webinar at work tomorrow. So I will think I will head to bed. I would really like to see if anyone else also have the same issue on windows... Maybe someone who doesn't rely on conda.

@scopatz
Copy link
Member Author

scopatz commented Oct 5, 2015

good night! I'll post to the mailing list.

@scopatz
Copy link
Member Author

scopatz commented Nov 7, 2015

I am going to go ahead and merge this with the assumption that some support is better than none. We can build off of this.

@scopatz scopatz merged commit 25cc8fb into master Nov 7, 2015
@scopatz scopatz deleted the jupyter branch November 7, 2015 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants