mpastell / Pweave

Pweave is a scientific report generator and a literate programming tool for Python. It can capture the results and plots from data analysis and works well with numpy, scipy and matplotlib.
http://mpastell.com/pweave
Other
435 stars 64 forks source link

Not compatible with `jupyter_client>=6` #151

Open vpipkt opened 4 years ago

vpipkt commented 4 years ago

It appears that the recent release of jupyter_client 6.0.0 introduces a breaking change

https://pypi.org/project/jupyter-client/#history

Environment Mac OS X, python 3.7.6

Also seen in linux environment on CI

$ pweave docs/reproject.pymd 
Traceback (most recent call last):
  File "/Users/jbrown/src/earthai/.virtualenv_p37/bin/pweave", line 8, in <module>
    sys.exit(weave())
  File "/Users/jbrown/src/earthai/.virtualenv_p37/lib/python3.7/site-packages/pweave/scripts.py", line 53, in weave
    pweave.weave(infile, **opts_dict)
  File "/Users/jbrown/src/earthai/.virtualenv_p37/lib/python3.7/site-packages/pweave/__init__.py", line 59, in weave
    doc.weave()
  File "/Users/jbrown/src/earthai/.virtualenv_p37/lib/python3.7/site-packages/pweave/pweb.py", line 192, in weave
    self.run()
  File "/Users/jbrown/src/earthai/.virtualenv_p37/lib/python3.7/site-packages/pweave/pweb.py", line 127, in run
    self.wd
  File "/Users/jbrown/src/earthai/.virtualenv_p37/lib/python3.7/site-packages/pweave/processors/jupyter.py", line 169, in __init__
    super(IPythonProcessor, self).__init__(*args, embed_kernel=embed)
  File "/Users/jbrown/src/earthai/.virtualenv_p37/lib/python3.7/site-packages/pweave/processors/jupyter.py", line 36, in __init__
    kc.start_channels()
  File "/Users/jbrown/src/earthai/.virtualenv_p37/lib/python3.7/site-packages/ipykernel/inprocess/client.py", line 64, in start_channels
    super(InProcessKernelClient, self).start_channels()
  File "/Users/jbrown/src/earthai/.virtualenv_p37/lib/python3.7/site-packages/jupyter_client/client.py", line 118, in start_channels
    self.control_channel.start()
  File "/Users/jbrown/src/earthai/.virtualenv_p37/lib/python3.7/site-packages/jupyter_client/client.py", line 200, in control_channel
    socket, self.session, self.ioloop
TypeError: ChannelABC() takes no arguments
lgarcin commented 4 years ago

Same error here ChannelABC() takes no arguments with

No problem with jupyter-client 5.3.4

JamesOwers commented 4 years ago

Same. I think the way kernels are instantiated must have changed. Here's the issue's exit point from pweave: https://github.com/mpastell/Pweave/blob/fa2a7f22a0f504012f8e274c0f120c3798c40510/pweave/processors/jupyter.py#L35.

My guess is a difference in the jupyter_client.KernelManager. https://github.com/jupyter/jupyter_client/blob/fa0c78b97bc7183e1a6c0fa2f88fee943e52580e/jupyter_client/manager.py#L32

Looking at the diffs to jupyter_client.manager I'm a bit stumped - https://github.com/jupyter/jupyter_client/compare/0f13a70c920123237c804c68a7bb2f469da2ad0c..9f7c213

JamesOwers commented 4 years ago

What I can say is that if you specify a kernel directly, it works. But you cannot do this from command line for pypublish 😢

thirschbuechler commented 4 years ago

A temporary fix seems to be to downgrade

Native Python / Linux:

sudo apt install python3-pip python3-setuptools
python3 -m pip install --upgrade jupyter_client==5.3.1

Anaconda, probably something like this (haven't tried):

conda install notebook==5.3.1
conda install jupyter_client==5.3.1

Apparently not the first time this happend for Jupyter: https://github.com/jupyter/notebook/issues/4937

vpipkt commented 4 years ago

I'll put up a PR to put an upper bound on the jupyter-client version. Maybe it will get merged until a bigger fix to the kernel manager can be sorted.

On Sun, Mar 8, 2020, 07:55 thirschbuechler notifications@github.com wrote:

A temporary fix seems to be to downgrade

Native Python / Linux:

sudo apt install python3-pip python3-setuptools python3 -m pip install --upgrade jupyter_client==5.3.1

Anaconda, probably something like this (haven't tried):

conda install notebook==5.3.1 conda install jupyter_client==5.3.1

Apparently not the first time this happend for Jupyter: jupyter/notebook#4937 https://github.com/jupyter/notebook/issues/4937

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mpastell/Pweave/issues/151?email_source=notifications&email_token=AB3P4L6FG3V7LBNLKZCJ4JTRGOBT3A5CNFSM4K2KLUQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOET7TY#issuecomment-596197327, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3P4L5AXTRFPEJZ3DKYUJTRGOBT3ANCNFSM4K2KLUQA .up

lgarcin commented 4 years ago

Everything seems to go back to normal with the release of jupyter-client 6.1.0.

Environment : Windows10, python 3.7.5, jupyter-client 6.1.0

vpipkt commented 4 years ago

Interesting. I will try to test locally ... But the CI job looks like it may have some other issues basically in need of a lot of maintenance since the last release.

vpipkt commented 4 years ago

I am still seeing the error on Mac OSX, python 3.7.6, jupyter-client 6.1.0

lgarcin commented 4 years ago

I upgraded from Python 3.7.5 to Python 3.8.2 and now I see a new error.

c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\pweave\__init__.py:51: SyntaxWarning: "is not" w
ith a literal. Did you mean "!="?
  assert file != "" is not None, "No input specified"
Traceback (most recent call last):
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py", line 528, in ge
t
    value = obj._trait_values[self.name]
KeyError: 'iopub_socket'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py", line 528, in ge
t
    value = obj._trait_values[self.name]
KeyError: 'iopub_thread'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\laure\appdata\local\programs\python\python38\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\laure\appdata\local\programs\python\python38\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\laure\AppData\Local\Programs\Python\Python38\Scripts\pweave.exe\__main__.py", line 7, in <module>
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\pweave\scripts.py", line 53, in weave
    pweave.weave(infile, **opts_dict)
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\pweave\__init__.py", line 63, in weave
    doc.weave()
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\pweave\pweb.py", line 192, in weave
    self.run()
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\pweave\pweb.py", line 122, in run
    proc = Processor(copy.deepcopy(self.parsed),
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\pweave\processors\jupyter.py", line 169,
 in __init__
    super(IPythonProcessor, self).__init__(*args, embed_kernel=embed)
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\pweave\processors\jupyter.py", line 34,
in __init__
    km.start_kernel(cwd=path, stderr=open(os.devnull, 'w'))
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\ipykernel\inprocess\manager.py", line 46
, in start_kernel
    self.kernel = InProcessKernel(parent=self, session=self.session)
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\ipykernel\inprocess\ipkernel.py", line 7
2, in __init__
    super(InProcessKernel, self).__init__(**traits)
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\ipykernel\ipkernel.py", line 71, in __in
it__
    self.shell.displayhook.pub_socket = self.iopub_socket
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py", line 556, in __
get__
    return self.get(obj, cls)
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py", line 535, in ge
t
    value = self._validate(obj, dynamic_default())
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\ipykernel\inprocess\ipkernel.py", line 6
7, in _default_iopub_socket
    return self.iopub_thread.background_socket
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py", line 556, in __
get__
    return self.get(obj, cls)
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py", line 535, in ge
t
    value = self._validate(obj, dynamic_default())
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\ipykernel\inprocess\ipkernel.py", line 5
9, in _default_iopub_thread
    thread = IOPubThread(self._underlying_iopub_socket)
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\ipykernel\iostream.py", line 71, in __in
it__
    self._setup_event_pipe()
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\ipykernel\iostream.py", line 90, in _set
up_event_pipe
    self._event_puller = ZMQStream(pipe_in, self.io_loop)
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\zmq\eventloop\zmqstream.py", line 127, i
n __init__
    self._init_io_state()
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\zmq\eventloop\zmqstream.py", line 546, i
n _init_io_state
    self.io_loop.add_handler(self.socket, self._handle_events, self.io_loop.READ)
  File "c:\users\laure\appdata\local\programs\python\python38\lib\site-packages\tornado\platform\asyncio.py", line 100,
in add_handler
    self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
  File "c:\users\laure\appdata\local\programs\python\python38\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError

I applied the fix described here. https://github.com/jupyter/notebook/issues/4613#issuecomment-548992047

I copied these lines at the beginning of __init__.py in the pweave package.

import asyncio, sys

if sys.platform == 'win32':
  asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

Everything now works as expected.