Giter VIP home page Giter VIP logo

ipykernel's Introduction

image

image

image

image

image

image

IPython: Productive Interactive Computing

Overview

Welcome to IPython. Our full documentation is available on ipython.readthedocs.io and contains information on how to install, use, and contribute to the project. IPython (Interactive Python) is a command shell for interactive computing in multiple programming languages, originally developed for the Python programming language, that offers introspection, rich media, shell syntax, tab completion, and history.

IPython versions and Python Support

Starting after IPython 8.16, we will progressively transition to Spec-0000.

Starting with IPython 7.10, IPython follows NEP 29

IPython 7.17+ requires Python version 3.7 and above.

IPython 7.10+ requires Python version 3.6 and above.

IPython 7.0 requires Python version 3.5 and above.

IPython 6.x requires Python version 3.3 and above.

IPython 5.x LTS is the compatible release for Python 2.7. If you require Python 2 support, you must use IPython 5.x LTS. Please update your project configurations and requirements as necessary.

The Notebook, Qt console and a number of other pieces are now parts of Jupyter. See the Jupyter installation docs if you want to use these.

Main features of IPython

Comprehensive object introspection.

Input history, persistent across sessions.

Caching of output results during a session with automatically generated references.

Extensible tab completion, with support by default for completion of python variables and keywords, filenames and function keywords.

Extensible system of ‘magic’ commands for controlling the environment and performing many tasks related to IPython or the operating system.

A rich configuration system with easy switching between different setups (simpler than changing $PYTHONSTARTUP environment variables every time).

Session logging and reloading.

Extensible syntax processing for special purpose situations.

Access to the system shell with user-extensible alias system.

Easily embeddable in other Python programs and GUIs.

Integrated access to the pdb debugger and the Python profiler.

Development and Instant running

You can find the latest version of the development documentation on readthedocs.

You can run IPython from this directory without even installing it system-wide by typing at the terminal:

$ python -m IPython

Or see the development installation docs for the latest revision on read the docs.

Documentation and installation instructions for older version of IPython can be found on the IPython website

IPython requires Python version 3 or above

Starting with version 6.0, IPython does not support Python 2.7, 3.0, 3.1, or 3.2.

For a version compatible with Python 2.7, please install the 5.x LTS Long Term Support version.

If you are encountering this error message you are likely trying to install or use IPython from source. You need to checkout the remote 5.x branch. If you are using git the following should work:

$ git fetch origin
$ git checkout 5.x

If you encounter this error message with a regular install of IPython, then you likely need to update your package manager, for example if you are using pip check the version of pip with:

$ pip --version

You will need to update pip to the version 9.0.1 or greater. If you are not using pip, please inquiry with the maintainers of the package for your package manager.

For more information see one of our blog posts:

https://blog.jupyter.org/release-of-ipython-5-0-8ce60b8d2e8e

As well as the following Pull-Request for discussion:

#9900

This error does also occur if you are invoking setup.py directly – which you should not – or are using easy_install If this is the case, use pip install . instead of setup.py install , and pip install -e . instead of setup.py develop If you are depending on IPython as a dependency you may also want to have a conditional dependency on IPython depending on the Python version:

install_req = ['ipython']
if sys.version_info[0] < 3 and 'bdist_wheel' not in sys.argv:
    install_req.remove('ipython')
    install_req.append('ipython<6')

setup(
    ...
    install_requires=install_req
)

Alternatives to IPython

IPython may not be to your taste; if that's the case there might be similar project that you might want to use:

Ignoring commits with git blame.ignoreRevsFile

As of git 2.23, it is possible to make formatting changes without breaking git blame. See the git documentation for more details.

To use this feature you must:

  • Install git >= 2.23
  • Configure your local git repo by running:
    • POSIX: tools\configure-git-blame-ignore-revs.sh
    • Windows: tools\configure-git-blame-ignore-revs.bat

ipykernel's People

Contributors

afshin avatar bfroehle avatar blink1073 avatar bollwyvl avatar carreau avatar ccordoba12 avatar davidbrochart avatar dwillmer avatar echarles avatar eendebakpt avatar ellisonbg avatar fcollonval avatar fperez avatar github-actions[bot] avatar glentakahashi avatar ianthomas23 avatar itamarst avatar itziakos avatar ivanov avatar jasongrout avatar jdfreder avatar johanmabille avatar maartenbreddels avatar martinrenou avatar minrk avatar pre-commit-ci[bot] avatar sylvaincorlay avatar takluyver avatar tkf avatar willingc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ipykernel's Issues

Jupyter fails to load kernel with ipykernel 4.3.1 but works with 4.1.1

I use conda to update packages, often conda update --all. My Python 3 conda environments suddenly failed on Windows 7. I traced it to updating ipykernel. I reverted to 4.1.1 and Jupyter loads correctly. Here was the traceback:

Traceback (most recent call last):
  File "C:\Anaconda3\envs\py35\lib\site-packages\notebook\base\handlers.py", line 457, in wrapper
    result = yield gen.maybe_future(method(self, *args, **kwargs))
  File "C:\Anaconda3\envs\py35\lib\site-packages\tornado\gen.py", line 1008, in run
    value = future.result()
  File "C:\Anaconda3\envs\py35\lib\site-packages\tornado\concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "C:\Anaconda3\envs\py35\lib\site-packages\tornado\gen.py", line 1014, in run
    yielded = self.gen.throw(*exc_info)
  File "C:\Anaconda3\envs\py35\lib\site-packages\notebook\services\sessions\handlers.py", line 62, in post
    kernel_id=kernel_id))
  File "C:\Anaconda3\envs\py35\lib\site-packages\tornado\gen.py", line 1008, in run
    value = future.result()
  File "C:\Anaconda3\envs\py35\lib\site-packages\tornado\concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "C:\Anaconda3\envs\py35\lib\site-packages\tornado\gen.py", line 1014, in run
    yielded = self.gen.throw(*exc_info)
  File "C:\Anaconda3\envs\py35\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 79, in create_session
    kernel_name)
  File "C:\Anaconda3\envs\py35\lib\site-packages\tornado\gen.py", line 1008, in run
    value = future.result()
  File "C:\Anaconda3\envs\py35\lib\site-packages\tornado\concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "C:\Anaconda3\envs\py35\lib\site-packages\tornado\gen.py", line 1014, in run
    yielded = self.gen.throw(*exc_info)
  File "C:\Anaconda3\envs\py35\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 92, in start_kernel_for_session
    self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
  File "C:\Anaconda3\envs\py35\lib\site-packages\tornado\gen.py", line 1008, in run
    value = future.result()
  File "C:\Anaconda3\envs\py35\lib\site-packages\tornado\concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "C:\Anaconda3\envs\py35\lib\site-packages\tornado\gen.py", line 282, in wrapper
    yielded = next(result)
  File "C:\Anaconda3\envs\py35\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 87, in start_kernel
    super(MappingKernelManager, self).start_kernel(**kwargs)
  File "C:\Anaconda3\envs\py35\lib\site-packages\jupyter_client\multikernelmanager.py", line 110, in start_kernel
    km.start_kernel(**kwargs)
  File "C:\Anaconda3\envs\py35\lib\site-packages\jupyter_client\manager.py", line 243, in start_kernel
    **kw)
  File "C:\Anaconda3\envs\py35\lib\site-packages\jupyter_client\manager.py", line 189, in _launch_kernel
    return launch_kernel(kernel_cmd, **kw)
  File "C:\Anaconda3\envs\py35\lib\site-packages\jupyter_client\launcher.py", line 123, in launch_kernel
    proc = Popen(cmd, **kwargs)
  File "C:\Anaconda3\envs\py35\lib\subprocess.py", line 950, in __init__
    restore_signals, start_new_session)
  File "C:\Anaconda3\envs\py35\lib\subprocess.py", line 1220, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

For reference, conda info produces:

Using Anaconda Cloud api site https://api.anaconda.org
Current conda install:

             platform : win-64
        conda version : 4.0.7
  conda-build version : 1.20.3
       python version : 3.5.1.final.0
     requests version : 2.10.0
     root environment : C:\Anaconda3  (writable)
  default environment : C:\Anaconda3\envs\py35
     envs directories : C:\Anaconda3\envs
        package cache : C:\Anaconda3\pkgs
         channel URLs : https://conda.anaconda.org/t/<TOKEN>/avishapiro/win-64/
                        https://conda.anaconda.org/t/<TOKEN>/avishapiro/noarch/
                        https://conda.anaconda.org/t/<TOKEN>/auto/win-64/
                        https://conda.anaconda.org/t/<TOKEN>/auto/noarch/
                        https://conda.anaconda.org/t/<TOKEN>/conda-forge/win-64/
                        https://conda.anaconda.org/t/<TOKEN>/conda-forge/noarch/
                        https://repo.continuum.io/pkgs/free/win-64/
                        https://repo.continuum.io/pkgs/free/noarch/
                        https://repo.continuum.io/pkgs/pro/win-64/
                        https://repo.continuum.io/pkgs/pro/noarch/
          config file : C:\Users\avi.shapiro\.condarc
    is foreign system : False

Don't reference ipython_widgets.

Right now ipython_widgets is referenced as IPython.html.widgets. We should be referencing it at all. Instead the kernel should provide means for specifying Python extensions on to be loaded with the kernel. The widgets would use this.

Filenames conflict with IPython kernel

Two days ago, I made a remark in #40, because I had the same error message. However, that issue is already closed, so I'm opening a new one.

Error while finding spec for 'ipykernel.__main__' (<class 'ImportError'>: cannot import name 'decorator'); 'ipykernel' is a package and cannot be directly executed

The problem arises if there's a file called decorator.py in the same folder you run jupyter notebook.

Here are the steps to reproduce the issue.

  1. $ mkdir bugtest
  2. $ cd bugtest
  3. $ touch decorator.py
  4. $ jupyter notebook
  5. Using the GUI, create a new IPython notebook.
  6. Go to the terminal. Now, the kernel should restart.

I also tried with several other filenames. I detected that with argparse.py, the kernel would also have some problems to start. That being the case, I think the kernel is erroneously trying to import modules.

Subproc interferes with startup, causes timeout

I am writing with regards to an issue that was first reported for Calysto/xonsh_kernel#2, but is something that we are also seeing with the mainline xonsh kernel as well.

On Jupyter v 4.0.6 and ipykernel v4.1.1 on at least Linux, we consistently see timeout issues, like the following when starting new xonsh kernels.

scopatz@localhost ~ $ jupyter notebook --no-browser
[I 15:47:39.302 NotebookApp] Serving notebooks from local directory: /home/scopatz
[I 15:47:39.302 NotebookApp] 0 active kernels 
[I 15:47:39.302 NotebookApp] The IPython Notebook is running at: http://localhost:8888/
[I 15:47:39.302 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[I 15:47:46.134 NotebookApp] Creating new notebook in 
[I 15:47:47.003 NotebookApp] Kernel started: 9e3c7307-c9e6-4896-bf5d-b5bc302608ea
[W 15:47:57.112 NotebookApp] Timeout waiting for kernel_info reply from 9e3c7307-c9e6-4896-bf5d-b5bc302608ea

This only seems to happen when xonsh is sourcing configurations from foreign shells (it loads Bash by default). This involves running a subprocess and waiting for some output.

Once the timeout fails, no input from the notebook interface is accepted and the subproc stays alive, eats up 100% CPU, and must be manually SIGKILL'd.

My guess, though I am not an expert on the Jupyter / IPython internals, is that this interferes with the ability to issue a heartbeat.

My questions are:

  • Is this really a heartbeat issue?
  • If so, is there a way to make ipykernel robust in the face of subprocess?
  • or do we need to run the subprocess on another thread so as to not block the heartbeat?
  • If it isn't a heartbeat, what is going on here?

It is worth noting that back in late Sept. and early Oct. 2015 this was working without significant changes in the xonsh startup procedure. I am reporting here because I believe that something about IPython, Jupyter, or PyZMQ has changed in this time.

Any help would be greatly appreciated! Thanks to @lmmx, @blink1073, and @IanSudbery for help in identifying this issue.

AttributeError: module 'faulthandler' has no attribute 'register' on Windows

Using ipykernel-4.3.0 on Windows (any Python version) raises AttributeError: module 'faulthandler' has no attribute 'register' because faulthandler.register is not available on Windows.

[I 16:56:07.962 NotebookApp] Kernel started: 3ada1467-e56a-41de-af2b-237fc7349760
Traceback (most recent call last):
  File "X:\Python35\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "X:\Python35\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "X:\Python35\lib\site-packages\ipykernel\__main__.py", line 3, in <module>
    app.launch_new_instance()
  File "X:\Python35\lib\site-packages\traitlets\config\application.py", line 588, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-123>", line 2, in initialize
  File "X:\Python35\lib\site-packages\traitlets\config\application.py", line 74, in catch_config_error
    return method(app, *args, **kwargs)
  File "X:\Python35\lib\site-packages\ipykernel\kernelapp.py", line 417, in initialize
    self.init_io()
  File "X:\Python35\lib\site-packages\ipykernel\kernelapp.py", line 316, in init_io
    self.patch_io()
  File "X:\Python35\lib\site-packages\ipykernel\kernelapp.py", line 326, in patch_io
    faulthandler_register = faulthandler.register
AttributeError: module 'faulthandler' has no attribute 'register'
[I 16:56:10.960 NotebookApp] KernelRestarter: restarting kernel (1/5)

Duplicate function `find_connection_file` with similar API to one in `jupyter_client`

From Gitter October 21, 2015 5:11 PM:

So, I was using find_connection_file from jupyter_client.connect. It turns out there is another implementation under ipykernel.connect, which does work. Is there a reason for two different implementations of this function?

Seems like there are two copies of the same function, but they act differently.

If this is intentional, it may be worth finding a different name to highlight the differences and deprecate the old one. If they are meant to behave more similarly, then a bug fix is in order and some discussion should occur about which one to deprecate, if possible, and why.

Related: jupyter/jupyter_client#85

Intermittent test failure - test_subprocess_print

Seen on Jenkins on a Linux build:
https://jenkins.jupyter.org/job/jack-of-none/142/console

OK when the build was repeated.

======================================================================
FAIL: printing from forked mp.Process
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/lib/jenkins/shiningpanda/jobs/92f5a430/virtualenvs/d41d8cd9/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/var/lib/jenkins/shiningpanda/jobs/92f5a430/virtualenvs/d41d8cd9/lib/python3.4/site-packages/IPython/external/decorators/_decorators.py", line 222, in knownfailer
    return f(*args, **kwargs)
  File "/var/lib/jenkins/shiningpanda/jobs/92f5a430/virtualenvs/d41d8cd9/lib/python3.4/site-packages/ipykernel/tests/test_kernel.py", line 83, in test_subprocess_print
    nt.assert_equal(stdout.count("hello"), np, stdout)
nose.proxy.AssertionError: 4 != 5 : hello 0
hello 2
hello 4
hello 1

-------------------- >> begin captured logging << --------------------
root: DEBUG: Found kernel python3 in /tmp/tmpqp6_2x_7/.local/share/jupyter/kernels
root: DEBUG: Starting kernel: ['/var/lib/jenkins/shiningpanda/jobs/92f5a430/virtualenvs/d41d8cd9/bin/python3.4', '-m', 'ipykernel', '-f', '/tmp/tmpwheu19w3.json']
root: DEBUG: Connecting to: tcp://127.0.0.1:58481
root: DEBUG: connecting shell channel to tcp://127.0.0.1:33469
root: DEBUG: Connecting to: tcp://127.0.0.1:33469
root: DEBUG: connecting iopub channel to tcp://127.0.0.1:59032
root: DEBUG: Connecting to: tcp://127.0.0.1:59032
root: DEBUG: connecting stdin channel to tcp://127.0.0.1:38519
root: DEBUG: Connecting to: tcp://127.0.0.1:38519
root: DEBUG: connecting heartbeat channel to tcp://127.0.0.1:50245
--------------------- >> end captured logging << ---------------------

Document how to install kernel for python 2 and 3

This is a pretty frequently asked question -- how to install the python 2 kernel and python 3 kernel simultaneously? The answer is usually "in a virtualenv" but it would be nice to have this documented somewhere with more specific instructions that we can point people to.

Correct installation of ipykernel in virtual environment

I was trying to install the IPython kernel (using python 2.x) in a new virtual environment but I didn't find very clear instructions.

I installed ipykernel and then used jupyter kernelspec install-self --user. Is this the correct approach? Is this the equivalent of IRkernel::installspec() in the IR kernel? Maybe I should use ipython kernelspec install-self (related to this issue)

[IPKernelApp] ERROR | UNKNOWN MESSAGE TYPE: 'comm_open'

Hello all, I am writing a wrapper kernel for xonsh (see xonsh/xonsh#399). We noticed that the following error gets printed to the command line on jupyter v4.0.6, jupyter notebook v4.0.5, and ipykernel v4.0.3.

[IPKernelApp] ERROR | UNKNOWN MESSAGE TYPE: 'comm_open'

Note that this error does not get printed if the jupyter notebook is on v4.0.4 and the other two stay the same. Not really sure what is going on here. It doesn't seem to effect anything on Ubuntu 15.04, but may be effecting things on Windows.

Don't allow to start as root by default.

Pendant of jupyter/notebook#1074 on IPython kernel side.

Should we allow starting the kernel as root without a flag ?
I think it is less problematic for the kernel as if the server is not root, you likely cannot start a kernel as root.
Maybe at least emit a warning ? Or not worth at all ?

async cell execution

Hi,

It'd be nice to be able to execute async code in IPython cells - this can allow using IPython to develop e.g. asyncio code (cell = implicit asyncio coroutine) or Scrapy spiders.

I'm having this problem in Splash Notebook kernel (https://github.com/scrapinghub/splash/blob/master/splash/kernel/kernel.py). This kernel runs a QWebKit browser in the same event loop as IPython and allows to control it using Lua scripts. Lua commands use coroutines; it means in Python land they use callbacks or deferreds. For example, there is splash:go(url) command which loads an URL in a browser and waits until all resources are loaded; this is implemented by loading URL and setting a callback for 'loadFinished' event.

Currently this is implemented using a hack: Kernel.do_execute returns a Deferred which is fired when load is finished, and Kernel.execute_request adds a callback to this Deferred to send the result back, instead of sending the result immediately.

This mostly works, but there are hacks required to make idle / busy handled correctly because ipykernel thinks results are always returned immediately. Kernel.dispatch_shell is handled incorrectly by these hacks, so sometimes kernel shows 'busy' state while it should be in 'idle' state; this breaks autocompletion for some reason (is it disabled when kernel is 'busy'?).

Sorry for a brain dump :) I don't really understand what I'm doing: what is dispatch_shell method for, what most arguments mean (parent? stream? ident? etc.). I've sent ipython/ipython#7713 in past to make IPython internals easier to work with for such async code, but never addressed the feedback. I think async support is most important for execute messages because they have real use cases; async completion and other messages are less useful, so it is fine to handle only execute messages.

I've seen #21 and https://github.com/takluyver/aiokernel, but didn't understood it at all; aiokernel look very different from what I came up with, so I have no idea what is it doing, or if it is solving the same issue or not.

Thoughts? Am I on a right track? Is this feature welcome? Is there a clean(er) way to implement it?

nosetests ipykernel

E:\install_work\ipykernel-4.3.1>nosetests ipykernel
.....................E.E...S.....................................................
======================================================================
ERROR: printing from forked mp.Process
----------------------------------------------------------------------
Traceback (most recent call last):
  File "e:\install_work\python2.7\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "e:\install_work\python2.7\lib\site-packages\numpy\testing\decorators.py", line 215, in knownfailer
    raise KnownFailureException(msg)
KnownFailureException: subprocess prints fail on Windows

======================================================================
ERROR: error in mp.Process doesn't crash
----------------------------------------------------------------------
Traceback (most recent call last):
  File "e:\install_work\python2.7\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "e:\install_work\python2.7\lib\site-packages\numpy\testing\decorators.py", line 215, in knownfailer
    raise KnownFailureException(msg)
KnownFailureException: subprocess prints fail on Windows

----------------------------------------------------------------------
Ran 81 tests in 26.038s

FAILED (SKIP=1, errors=2)

E:\install_work\ipykernel-4.3.1>

Python log in the jupyter notebook appears only in the terminal, not in the output cell

I am using jupyter notebook and since short time ago logs stopped to appear in output cells and started to appear only in the terminal.

I have described the problem here:
http://stackoverflow.com/questions/35936086/jupyter-notebook-does-not-print-logs-to-the-output-cell/35940918#35940918

Logging to output cell works correctly for ipykernel==4.2.2 and earlier, but since ipykernel==4.3.0 https://github.com/ipython/ipykernel/releases/tag/4.3.0 logs goes to terminal instead of the output cell.

I am not sure, but my guess is that the problem is caused by this commit: 65b6144

I have already opened one issue in the jupyter repository jupyter/jupyter#120, but I was advised to better open it here.

connect.py imports IPython.paths, should be IPython.utils.path

I am currently working on ebuilds for the Gentoo-science overlay. Running the tests, I get the following on my system:

  File "/tmp/portage/dev-python/ipython-ipykernel-9999/work/ipython-ipykernel-9999/ipykernel/connect.py", line 13, in <module>
    from IPython.paths import get_ipython_dir
ImportError: No module named 'IPython.paths'

Following the documentation, it seems that IPython.paths was renamed to IPython.utils.path. Replacing it, solves the issue on my system, on which ipython-3.1.0 is installed.

Asyncio Support For ZeroMQ-Based Kernels

Is there a chance to get native support for asyncio support for zeroMQ-based kernels?

I came up with this, which works already quite nice (needed a quick solution).

import asyncio
import itertools
from IPython.kernel.zmq.eventloops import register_integration


# FIXME: needs cleanup!
# https://github.com/ipython/ipykernel/blob/197a4a81c38dfcafb1cddb3029329137c8748b23/ipykernel/eventloops.py


@register_integration('asyncio')
def loop_asyncio(kernel):
    '''Start a kernel with asyncio event loop support.'''
    loop = asyncio.get_event_loop()

    def kernel_handler():
        loop.call_soon(kernel.do_one_iteration)
        loop.call_later(kernel._poll_interval, kernel_handler)

    loop.call_soon(kernel_handler)
    try:
        if not loop.is_running():
            loop.run_forever()
    finally:
        loop.close()

Invoking this cell prior the %gui asyncio cell already did the job.

How do specify host for ZMQ?

When I run python -m ipykernel -f <connection file>, the ZMQ ports are bound on localhost. Is there any way to specify a different host?

I tried changing the IP key in the connection.json file, but it didn't work.

echokernel example does not include topic in 'stream' responses

I believe there is a bug in the echokernel example kernel, specifically:

        if not silent:
            stream_content = {'name': 'stdout', 'text': code}
            self.send_response(self.iopub_socket, 'stream', stream_content)

This is sending a message across the PUBSUB iopub_socket, but it doesn't include an identity argument, so there is no PUBSUB being prefixed to the message. The fix seems to be:

        if not silent:
            stream_content = {'name': 'stdout', 'text': code}
            self.send_response(self.iopub_socket, 'stream', stream_content, ident=self._topic('stream'))

But I'm a tad hesitant to put it in a pull request because it seems intentional to make the _topic private. Does anyone know the right way to fix this?

Process hang while executing logging.warning under specific circumstances

I identified a kernel hang when calling the python logging facility under certain circumstances. The hang is specific for usage of function in jupyter, i.e. it does not happen in a ipython command shell.

The hang happens when I import a specific module form this repository: https://github.com/secdev/scapy/ (the issue can be reproduced with the version from pip as well).

from scapy.route6 import *

The hang happens in line 234 when this method is called

warning("No route found for IPv6 destination %s (no default route?)" % dst)

warning() is a wrapper that calls

logging.getLogger("scapy.runtime").logging(x)

where x is the message. I am not able to reproduce this issue in a smaller test case, i.e. I cannot find other situations where a call to logging.warning() hangs the kernel.

The reason why I open this issue with jupyter is that the jupyter notebook is the only environment where this results in a hang. The code works without issues in the standard python2.7 interpreter, and in the ipython command shell

I experience the issue on Mac OS X with the following python, and package versions

$ python --version
Python 2.7.10  

ipython and jupyter versions are:

ipykernel==4.3.1
ipython==4.2.0
ipython-genutils==0.1.0
ipywidgets==5.1.2
jupyter==1.0.0
jupyter-client==4.2.2
jupyter-console==4.1.1
jupyter-core==4.1.0

Is there any additional information that I can provide to further debug this problem?

Run IOPub in a thread

We should be sending IOPub messages in their own thread. This would solve various issues with flushing/threading/etc.

It shouldn't be complicated, other than preserving backward-compatibility for APIs which assume direct access to a Socket (consumed by widgets, ipyparallel).

Capture output coming from C and C++ libraries

Hi,

thanks for this excellent Kernel!
This is already a known behaviour: the output that is printed on screen by C/C++ libraries is not captured in the notebook: this can happen with ctypes or with Python bindings for C++ functions.
It would be terrific to have this output both captured and correctly interleaved with the output coming from Python and then printed "progressively" in the notebook.
For example, this loop could print every .5 secs a line from the Python and C world, interleaved:

from ctypes import *
libc = CDLL("libc.dylib")
import time
for i in xrange(10):
print "This is Python"
libc.printf("This is C\n")
time.sleep(.5)

At CERN we solved this issue for the ROOT Kernel in a custom way. For Python, we converged on a partial solution, which allows to correctly interleave the outputs but not to print them "live" in an asynchronous way.

I wonder if a general solution to this rather common issue, at least in HEP, could be envisaged, e.g. a "baby sitting process" capturing the output.

Cheers,
Danilo

Error when trying to import Kernel class

I am trying to import Kernel from ipykernel and getting the following error:

>>> from ipykernel import Kernel
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-9-3b8546febbac> in <module>()
----> 1 from ipykernel import Kernel

/Users/tom/miniconda3/envs/production/lib/python3.4/site-packages/ipykernel/__init__.py in <module>()
      1 from ._version import version_info, __version__
----> 2 from .connect import *

/Users/tom/miniconda3/envs/production/lib/python3.4/site-packages/ipykernel/connect.py in <module>()
     11 
     12 from IPython.core.profiledir import ProfileDir
---> 13 from IPython.paths import get_ipython_dir
     14 from ipython_genutils.path import filefind
     15 from ipython_genutils.py3compat import str_to_bytes

ImportError: No module named 'IPython.paths'

Here are the versions I'm using:

ipykernel==4.0.3
ipython==4.0.0
ipython-genutils==0.1.0
jupyter-client==4.0.0
jupyter-console==4.0.0
jupyter-core==4.0.4
path.py==0.0.0
pyzmq==14.7.0
traitlets==4.0.0

do_inspect lets ipython compute the info twice

Found this while trying to understand what is needed to make a decorated method get the same signature/completions as the original one, even on py2.7.

From https://github.com/ipython/ipykernel/blob/master/ipykernel/ipkernel.py#L247:

    def do_inspect(self, code, cursor_pos, detail_level=0):
        name = token_at_cursor(code, cursor_pos)
        info = self.shell.object_inspect(name) # computes the complete info
[...]
        if info['found']:
            info_text = self.shell.object_inspect_text(
                name,
                detail_level=detail_level,
            ) # computes it again as a first step
            data['text/plain'] = info_text
[...]

IMO it would be ok to replace the first self.shell.object_inspect(...) with a info = self.shell._object_find(name) and then use if info.found:. The problem is I don't understand what the with self.builtin_trap: in the object_inspect method does (source) and if that's already needed for self.shell._object_find.

Unable to run kernel

When I try to open a notebook using the Python 3 kernel, I get the following output.

[I 12:29:22.834 NotebookApp] Kernel started: 5e226817-b874-4f6c-9573-be8bcc723690
/data/tmacey/.virtualenvs/data-analytics/bin/python: Error while finding spec for 'ipykernel.__main__' (<class 'ImportError'>: No module named 'logconfig'); 'ipykernel' is a package and cannot be directly executed
[I 12:29:25.834 NotebookApp] KernelRestarter: restarting kernel (1/5)
/data/tmacey/.virtualenvs/data-analytics/bin/python: Error while finding spec for 'ipykernel.__main__' (<class 'ImportError'>: No module named 'logconfig'); 'ipykernel' is a package and cannot be directly executed
[I 12:29:28.840 NotebookApp] KernelRestarter: restarting kernel (2/5)
/data/tmacey/.virtualenvs/data-analytics/bin/python: Error while finding spec for 'ipykernel.__main__' (<class 'ImportError'>: No module named 'logconfig'); 'ipykernel' is a package and cannot be directly executed
[I 12:29:31.843 NotebookApp] KernelRestarter: restarting kernel (3/5)
/data/tmacey/.virtualenvs/data-analytics/bin/python: Error while finding spec for 'ipykernel.__main__' (<class 'ImportError'>: No module named 'logconfig'); 'ipykernel' is a package and cannot be directly executed
[W 12:29:33.487 NotebookApp] Timeout waiting for kernel_info reply from 5e226817-b874-4f6c-9573-be8bcc723690
[I 12:29:34.846 NotebookApp] KernelRestarter: restarting kernel (4/5)
WARNING:root:kernel 5e226817-b874-4f6c-9573-be8bcc723690 restarted
/data/tmacey/.virtualenvs/data-analytics/bin/python: Error while finding spec for 'ipykernel.__main__' (<class 'ImportError'>: No module named 'logconfig'); 'ipykernel' is a package and cannot be directly executed
[W 12:29:37.852 NotebookApp] KernelRestarter: restart failed
[W 12:29:37.852 NotebookApp] Kernel 5e226817-b874-4f6c-9573-be8bcc723690 died, removing from map.
ERROR:root:kernel 5e226817-b874-4f6c-9573-be8bcc723690 restarted failed!
[W 12:29:37.863 NotebookApp] Kernel deleted before session
[W 12:29:37.864 NotebookApp] 410 DELETE /api/sessions/d8d3f8c2-1fdc-4d5d-b52d-07afb925587b (::1) 1.70ms referer=http://localhost:8888/notebooks/Untitled.ipynb

I am using IPython, Jupyter and ipykernel v4.0.3 with Python 3.4.3 on Linux.
Linux kommandcenter 4.1.5-1-MANJARO #1 SMP PREEMPT Tue Aug 11 05:14:23 UTC 2015 x86_64 GNU/Linux

improve python -m ipykernel help

Ok, I know I am annoying and this is likely an edge case, but when starting with python -m the script name is __main__.py ... which does not look nice :-)

$ python -m ipykernel install --help
usage: __main__.py [-h] [--user] [--name NAME] [--display-name DISPLAY_NAME]
                   [--prefix PREFIX]

Install the IPython kernel spec.

Empty session keys

In a couple of places, the inprocess kernel code creates Session objects with empty keys. These cause a warning in the Session constructor now: jupyter/jupyter_client#106

If an empty key is a valid use-case, then jupyter/jupyter_client#106 needs to be rethought. Otherwise, the inprocess kernel code could use a constant non-empty default key, maybe b'inprocess'.

calling "%matplotlib inline" again resets figure formats

This should only print a link to the PDF, but actually outputs a png

%matplotlib inline
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('pdf')
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1,2,3,4,5,6,7,8])

This was a bugreport in knitpy (jankatins/knitpy#29 (comment)), where knitpy calls the first three lines (for PDF output) and a user then added the %matplotlib inline call again in a code chunk. From the naming of the argument, I wouldn't have guessed that the image formatter would be touched (at least not again).

How to embed IPython.core.interactiveshell.InteractiveShell silently?

I'm writing a server application that evaluates code strings it receives in certain namespaces, depending on the context. I'm trying to use the IPython-provided InteractiveShell class to run the user code. Couple of questions:

  1. What's the correct way to instantiate the shell, provide an initial namespace, and run code in it? The API as specified here doesn't say how to instantiate the shell in an embedded app (i.e. in a way that doesn't take over the app by blocking execution and providing an input prompt, but silently as an object I can pass code to).
  2. Meta-question: What I want is essentially an InteractiveConsole, with autocompletion and magics enabled. Is InteractiveShell the right class to be using, or is there a lower-level class that would be better suited? I'm not conforming to IPython's messaging protocol or ZMQ topology, so it doesn't make sense to subclass the KernelBase class or write a wrapper kernel around ipykernel.

Error when trying to import ipykernel: No module named 'IPython.paths'

I am trying to import ipykernel and getting the following error:

In [10]: import ipykernel
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-10-280cf9cbe7f8> in <module>()
----> 1 import ipykernel

/Users/tom/miniconda3/envs/production/lib/python3.4/site-packages/ipykernel/__init__.py in <module>()
      1 from ._version import version_info, __version__
----> 2 from .connect import *

/Users/tom/miniconda3/envs/production/lib/python3.4/site-packages/ipykernel/connect.py in <module>()
     11 
     12 from IPython.core.profiledir import ProfileDir
---> 13 from IPython.paths import get_ipython_dir
     14 from ipython_genutils.path import filefind
     15 from ipython_genutils.py3compat import str_to_bytes

ImportError: No module named 'IPython.paths'

Here are the versions I'm using:

ipykernel==4.0.3
ipython==4.0.0
ipython-genutils==0.1.0
jupyter-client==4.0.0
jupyter-console==4.0.0
jupyter-core==4.0.4
path.py==0.0.0
pyzmq==14.7.0
traitlets==4.0.0

This is with Python 3.4

Tab completion ignores __all__

The Python docs describe "public names" as being defined by __all__ where it exists. It would be helpful if this rule was respected by the Python kernel to avoid module authors that want to provide helpful tab-completion having to obfuscate imports, etc. with leading underscores. NB. This use case is explicitly recognised in the Python docs:

... to avoid accidentally exporting items that are not part of the API (such as library modules which were imported and used within the module).

WIth the current kernel behaviour, code such as:

from __future__ import (division, print_function)
from six.moves import (filter, map)

import contextlib

__all__ = ['my_api']

def my_api():
    ...

needs to become:

from __future__ import (division as _, print_function as _)
from six.moves import (filter as _filter, map as _map)

import contextlib as _contextlib

__all__ = ['my_api']

def my_api():
    ...

New hook point for messages / message transforms.

We intend to make a new hook point to allow the installation of hooks on the display publisher.

Current thoughts (largely from @minrk + @jasongrout):

  • Update ZMQDisplayPublisher to do a 2-stage message build.
  • Pass the message to the transform(s), which return a message or None.
  • If a message is returned, send it in the usual manner.

This will require:

  • Changing the display publisher to have a new method for registering a hook.
  • Changes to iostream / ipywidgets / other related repos.

Allow comm message to be processed during cell execution

The use case: a Python function getMouse() that blocks waiting for the user to click on an SVG image that has been wired up to a trait to pass the x,y value back to Python. We would like getMouse() to return that x,y.

The implementation we are thinking of would allow comm messages to be processed during the cell execution. I think this is general to any comm_msg, but our goal is just the mouse widget. Here is a little version of the idea:

from ipywidgets import widgets
from IPython.display import display
i = widgets.IntText()
display(i)
i.value = 78
while i.value == 78:
    pass

We would like to be able to change the value in the displayed IntText (for example) and have the loop stop when the detected value changes. We understand that jupyter is not designed to do this, but we would like to replicate a pre-existing API in the notebook, getMouse().

Is it possible, while the cell is executing, to process any queued comm messages? Thinking of something like:

while i.value == 78:
    kernel = get_ipython_kernel()
    kernel.process_comm_msgs()

Any help or alternative ideas welcomed!

[IPKernelApp] ERROR | No such comm target registered: ipython.widget

When trying to use ipykernel to run Python 2 in JupyterHub I'm getting this error and some weird behavior: the kernel starts and lets me type whatever I want, but doesn't return anything (neither results, nor errors). Nothing appears in the logs as well.

After some time of the kernel 'running' the following message starts to pop up in the logs in cycles:

Traceback (most recent call last):
File "/usr/local/bin/sudospawner", line 4, in
mediator.main()
File "/usr/local/lib/python3.3/site-packages/sudospawner/mediator.py", line 138, in main
kill(**kwargs)
File "/usr/local/lib/python3.3/site-packages/sudospawner/mediator.py", line 54, in kill
finish({'alive': alive})
File "/usr/local/lib/python3.3/site-packages/sudospawner/mediator.py", line 34, in finish
if data and data['ok']:
KeyError: 'ok'

I'm running JupyterHub 0.6.0 with Jupyter 1.0.0 and ipykernel 4.3.1.
I'm not using anaconda, just plain old python. My kernel.json looks like this (and it points to the right python executable):

{
 "display_name": "Python 2", 
 "language": "python", 
 "argv": [
  "/usr/local/bin/python2.7", 
  "-m", 
  "ipykernel", 
  "-f", 
  "{connection_file}"
 ]
}

conda install ipywidgets requires another jupyter notebook install?

I'm trying to run jupyter notebook from a root conda environment, with the kernels installed in the correct --data-dir, with an absolute path pointing to the conda environment for that kernel:

{
 "display_name": "Python 3",
 "argv": [
  "/Users/klay6683/miniconda3/envs/py34/bin/python",
  "-m",
  "ipykernel",
  "-f",
  "{connection_file}"
 ],
 "language": "python"
}

but without installing another jupyter notebook in the conda environments.
But some of my libraries use widgets, so they do import from ipywidgets, which I don't have installed. Independently (it seems), even before I try to import my modules that use ipywidgets, just to see what happens, in the notebook console I see this happening, (which is why I report here:)

[I 00:40:58.805 NotebookApp] Kernel started: 65371f66-b64e-459b-a669-c8cda9f856fe
[IPKernelApp] ERROR | No such comm target registered: ipython.widget

But when I try to install only the ipywidgets, conda wants to install the whole she-bang it seems:

$ conda install ipywidgets
Fetching package metadata: ....
Solving package specifications: ..................................
Package plan for installation in environment /Users/klay6683/miniconda3/envs/py34:

The following NEW packages will be INSTALLED:

    certifi:    2015.9.6.2-py34_0
    ipywidgets: 4.1.0-py34_0
    jsonschema: 2.4.0-py34_0
    mistune:    0.7.1-py34_0
    nbconvert:  4.0.0-py34_0
    nbformat:   4.0.1-py34_0
    notebook:   4.0.6-py34_0
    ptyprocess: 0.5-py34_0
    pygments:   2.0.2-py34_0
    terminado:  0.5-py34_1
    tornado:    4.2.1-py34_0

after which above error message disappears.

My relevant conda packages installed before the above were:

$ conda list|grep -i jupy
jupyter_client            4.1.1                    py34_0
jupyter_core              4.0.6                    py34_0
(py34)
klay6683 at macd2860 in ~
$ conda list|grep -i ipy
ipykernel                 4.1.1                    py34_0
ipython                   4.0.0                    py34_1
ipython_genutils          0.1.0                    py34_0

My question is, is this unavoidable, a conda problem, or am I still doing something wrong?
On a side note, when I tried the full path method to install kernels like so:

/Users/klay6683/miniconda/envs/py34/bin/python -m IPython kernelspec install-self

this installed the kernel into /usr/local/share/jupyter/kernels instead of into jupyter --data-dir which is /Users/klay6683/Library/Jupyter on my system.

Comms broken in master

#126 seems to have broken the handling of comm messages from the frontend. We could revert the PR.

@jasongrout verbally volunteered to debug this before we revert.

json_clean doesn't know how to serialize pandas/numpy types

I'm using the jupyter-incubator/declarativewidgets in a notebook in 4.x. When I try to send a dictionary that I created from a pandas Series (to_dict()), I'm running into a JSON serialization error. Apparently, sending numpy data types over the widget channels causes the error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-329f8d502429> in <module>()
----> 1 channel('pickup').set('pickup', pickup.to_dict())

/opt/conda/lib/python3.4/site-packages/urth/widgets/widget_channels.py in set(self, key, value, **kwargs)
     68     def set(self, key, value, **kwargs):
     69         global the_channels
---> 70         the_channels.set(key, value, self.chan, **kwargs)
     71 
     72     def watch(self, key, handler):

/opt/conda/lib/python3.4/site-packages/urth/widgets/widget_channels.py in set(self, key, value, chan, **kwargs)
     37         attr = "{}:{}".format(chan, key)
     38         serialized = self.serializer.serialize(value, **kwargs)
---> 39         self._send_update(attr, serialized)
     40 
     41     def watch(self, key, handler, chan='default'):

/opt/conda/lib/python3.4/site-packages/urth/widgets/urth_widget.py in _send_update(self, attribute, value)
     29             }
     30         }
---> 31         self._send(msg)
     32 
     33     def send_status(self, status, msg=""):

/opt/conda/lib/python3.4/site-packages/ipywidgets/widgets/widget.py in _send(self, msg, buffers)
    449     def _send(self, msg, buffers=None):
    450         """Sends a message to the model in the front-end."""
--> 451         self.comm.send(data=msg, buffers=buffers)
    452 
    453 

/opt/conda/lib/python3.4/site-packages/ipykernel/comm/comm.py in send(self, data, metadata, buffers)
    125         """Send a message to the frontend-side version of this comm"""
    126         self._publish_msg('comm_msg',
--> 127             data=data, metadata=metadata, buffers=buffers,
    128         )
    129 

/opt/conda/lib/python3.4/site-packages/ipykernel/comm/comm.py in _publish_msg(self, msg_type, data, metadata, buffers, **keys)
     73         data = {} if data is None else data
     74         metadata = {} if metadata is None else metadata
---> 75         content = json_clean(dict(data=data, comm_id=self.comm_id, **keys))
     76         self.session.send(self.iopub_socket, msg_type,
     77             content,

/opt/conda/lib/python3.4/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    161         out = {}
    162         for k,v in iteritems(obj):
--> 163             out[unicode_type(k)] = json_clean(v)
    164         return out
    165     if isinstance(obj, datetime):

/opt/conda/lib/python3.4/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    161         out = {}
    162         for k,v in iteritems(obj):
--> 163             out[unicode_type(k)] = json_clean(v)
    164         return out
    165     if isinstance(obj, datetime):

/opt/conda/lib/python3.4/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    161         out = {}
    162         for k,v in iteritems(obj):
--> 163             out[unicode_type(k)] = json_clean(v)
    164         return out
    165     if isinstance(obj, datetime):

/opt/conda/lib/python3.4/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    161         out = {}
    162         for k,v in iteritems(obj):
--> 163             out[unicode_type(k)] = json_clean(v)
    164         return out
    165     if isinstance(obj, datetime):

/opt/conda/lib/python3.4/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    167 
    168     # we don't understand it, it's probably an unserializable object
--> 169     raise ValueError("Can't clean for JSON: %r" % obj)

ValueError: Can't clean for JSON: 1

Here's a notebook that reproduces the error condition: https://gist.github.com/jtyberg/63fe41605566fc1fe866

Couldn't add child view to box when rendering widgets

Hi,

I recently created a kernel that inherits directly from IPythonKernel: class MyKernel(IPythonKernel)
The reason I inherit directly from IPythonKernel and not KernelBase is that I was having trouble getting magics support from KernelBase out of the box.

Anyways, when I try to display a Widget in MyKernel, I get a Javascript error that I am having a very hard time debugging. Message from browser console below. Notice that the widget tabs omit the content of the widget children:
screen shot 2015-11-03 at 6 43 00 pm

When i run the same piece of code that renders the same widget on the real IPythonKernel, it looks like this, with children displaying correctly:
screen shot 2015-11-03 at 6 45 17 pm

Any help would be appreciated!

Thanks!

Javascript error message:

Uncaught (in promise) WrappedError {stack: "Error: Couldn't add child view to box↵    at new E…in.js?v=40e10638fcf65fc1c057bff31d165e9d:12785:33", message: "Couldn't add child view to box", error_stack: Array[4]}error_stack: Array[4]0: TypeError: require is not a function
    at http://localhost:8888/static/notebook/js/main.min.js?v=40e10638fcf65fc1c057bff31d165e9d:12740:17
    at Object.load_class (http://localhost:8888/static/notebook/js/main.min.js?v=40e10638fcf65fc1c057bff31d165e9d:12736:16)
    at http://localhost:8888/nbextensions/widgets/widgets/js/manager.js?v=20151103005149:74:261: Error: Couldn't create a view for model id '5ce5e524d89f44fd84f229604853b122'
    at new Error (native)
    at Error.WrappedError (http://localhost:8888/static/notebook/js/main.min.js?v=40e10638fcf65fc1c057bff31d165e9d:12706:25)
    at http://localhost:8888/static/notebook/js/main.min.js?v=40e10638fcf65fc1c057bff31d165e9d:12785:33message: "Couldn't create a view for model id '5ce5e524d89f44fd84f229604853b122'"stack: (...)get stack: ()set stack: ()__proto__: DefineError.bh2: Error: Couldn't create child view
    at new Error (native)
    at Error.WrappedError (http://localhost:8888/static/notebook/js/main.min.js?v=40e10638fcf65fc1c057bff31d165e9d:12706:25)
    at http://localhost:8888/static/notebook/js/main.min.js?v=40e10638fcf65fc1c057bff31d165e9d:12785:33message: "Couldn't create child view"stack: (...)get stack: ()set stack: ()__proto__: DefineError.bh3: Error: Couldn't add child view to box
    at new Error (native)
    at Error.WrappedError (http://localhost:8888/static/notebook/js/main.min.js?v=40e10638fcf65fc1c057bff31d165e9d:12706:25)
    at http://localhost:8888/static/notebook/js/main.min.js?v=40e10638fcf65fc1c057bff31d165e9d:12785:33length: 4__proto__: Array[0]message: "Couldn't add child view to box"stack: "Error: Couldn't add child view to box↵    at new Error (native)↵    at Error.WrappedError (http://localhost:8888/static/notebook/js/main.min.js?v=40e10638fcf65fc1c057bff31d165e9d:12706:25)↵    at http://localhost:8888/static/notebook/js/main.min.js?v=40e10638fcf65fc1c057bff31d165e9d:12785:33"__proto__: Object

Should `ipython kernel install` shell out to Jupyter instead of the Python API?

Currently, when you install the IPython kernelspec, it uses the jupyter_client Python API to do it. This ensures that it's using the same Python as IPython, and is part of why we say it doesn't make sense to install kernels in sys.prefix.

If, instead, we shelled out to jupyter kernelspec install, then it would be using the 'active' jupyter to decide where to put things. With that, it actually does start to make sense to put kernelspecs in sys.prefix (for envs, at least).

faulthandler.enable() fails with IOError

Reported by @poldrack on the notebook, but ultimately the issue is really a kernel problem, I can reproduce it from a plain console by connecting to an open kernel using ipykernel master:

denali[newjob]> jupyter console --existing kernel-95921.json
Jupyter Console 4.1.0.dev

[ZMQTerminalIPythonApp] Loading IPython extension: storemagic

In [1]: import faulthandler

In [2]: faulthandler.enable()
---------------------------------------------------------------------------
UnsupportedOperation                      Traceback (most recent call last)
<ipython-input-2-140d8a320d56> in <module>()
----> 1 faulthandler.enable()

/Users/fperez/dev/ipython/ipykernel/ipykernel/iostream.py in fileno(self)
    203 
    204     def fileno(self):
--> 205         raise UnsupportedOperation("IOStream has no fileno.")
    206 
    207     def write(self, string):

UnsupportedOperation: IOStream has no fileno.

BUG: Multiple incompatible subclass instances of ZMQInteractiveShell are being created

I think this is an ipykernel bug, but maybe it is an ipython bug. Sorry if I got the wrong repo. I tried to reproduce this issue ( ipython/ipython#7122 ). However, I got this other unrelated issue instead.

Environment details are as follows.

$ conda list
# packages in environment at /zopt/conda/envs/ipy:
#
appnope                   0.1.0                    py27_0    defaults
decorator                 4.0.4                    py27_0    defaults
ipykernel                 4.1.1                    py27_0    defaults
ipython                   4.0.0                    py27_1    defaults
ipython-genutils          0.1.0                     <pip>
ipython_genutils          0.1.0                    py27_0    defaults
jupyter-client            4.1.1                     <pip>
jupyter-core              4.0.6                     <pip>
jupyter_client            4.1.1                    py27_0    defaults
jupyter_core              4.0.6                    py27_0    defaults
numpy                     1.10.1                   py27_0    defaults
openssl                   1.0.2d                        0    defaults
path.py                   8.1.2                    py27_0    defaults
pexpect                   3.3                      py27_0    defaults
pickleshare               0.5                      py27_0    defaults
pip                       7.1.2                    py27_0    defaults
python                    2.7.10                        2    defaults
python.app                1.2                      py27_4    defaults
pyzmq                     14.7.0                   py27_1    defaults
readline                  6.2                           2    <unknown>
setuptools                18.4                     py27_0    defaults
simplegeneric             0.8.1                    py27_0    defaults
sqlite                    3.8.4.1                       1    <unknown>
tk                        8.5.18                        0    <unknown>
traitlets                 4.0.0                    py27_0    defaults
wheel                     0.26.0                   py27_1    defaults
zeromq                    4.1.3                         0    defaults
zlib                      1.2.8                         0    <unknown>

Code to reproduce.

$ ipython
Python 2.7.10 |Continuum Analytics, Inc.| (default, Oct 19 2015, 18:31:17) 
Type "copyright", "credits" or "license" for more information.

IPython 4.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from IPython.kernel.zmq.datapub import publish_data
/zopt/conda/envs/ipy/lib/python2.7/site-packages/IPython/kernel/__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead.
  "You should import from ipykernel or jupyter_client instead.", ShimWarning)

In [2]: import numpy as np

In [3]: myarr = np.ones(2 * 1024 * 1024 * 1024 * 8 // 64) # 2 GB

In [4]: publish_data({'x': myarr})
---------------------------------------------------------------------------
MultipleInstanceError                     Traceback (most recent call last)
<ipython-input-4-49f20562eb3f> in <module>()
----> 1 publish_data({'x': myarr})

/zopt/conda/envs/ipy/lib/python2.7/site-packages/ipykernel/datapub.pyc in publish_data(data)
     55     """
     56     from ipykernel.zmqshell import ZMQInteractiveShell
---> 57     ZMQInteractiveShell.instance().data_pub.publish_data(data)

/zopt/conda/envs/ipy/lib/python2.7/site-packages/traitlets/config/configurable.pyc in instance(cls, *args, **kwargs)
    389             raise MultipleInstanceError(
    390                 'Multiple incompatible subclass instances of '
--> 391                 '%s are being created.' % cls.__name__
    392             )
    393 

MultipleInstanceError: Multiple incompatible subclass instances of ZMQInteractiveShell are being created.

Python 2.x not working in virtual environment with Python 3.5

When I create a conda environment with Python 3.5 and then install the notebook, several kernels are correctly detected by the KernelSpecManager (python2 and python3, among others.) However, selecting python2 in the list of kernels actually launches python3:

screenshot from 2015-10-19 22 15 41

This is the list of kernels:

In [1]: from jupyter_client.kernelspec import KernelSpecManager

In [2]: KernelSpecManager().find_kernel_specs()
Out[2]:
{'bash': '/home/user/.local/share/jupyter/kernels/bash',
 'ir': '/home/user/.local/share/jupyter/kernels/ir',
 'julia-0.4': '/home/user/.local/share/jupyter/kernels/julia-0.4',
 'python2': '/home/user/.local/share/jupyter/kernels/python2',
 'python3': '/home/user/anaconda/envs/py3_jupyter/lib/python3.5/site-packages/ipykernel/resources'}

Why did this happen in the first place? Is this a bug?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.