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

Import error (jupyter_client missing) on notebook execution #311

Open
euronion opened this issue Aug 14, 2019 · 7 comments
Open

Import error (jupyter_client missing) on notebook execution #311

euronion opened this issue Aug 14, 2019 · 7 comments

Comments

@euronion
Copy link

I cannot compile my SPHINX documentation when I try to include a notebook without any cell output.

Error log

Notebook error:
ImportError in examples\<notebook_name>.ipynb:
`nbconvert --execute` requires the jupyter_client package: `pip install jupyter_client`

	at ChildProcess.exithandler (child_process.js:299:12)
	at ChildProcess.emit (events.js:182:13)
	at maybeClose (internal/child_process.js:962:16)
	at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)

(jupyter_client is installed, see below)

Workaround

After a lot of head scratching I realised the problem seems to be related to the automatic execution of the noetbook, therefore I tried:

  • Prerunning the notebook (thus having cell output)
  • Setting nbsphinx_execute = 'never' in conf.py

Which both result in the documentation to be created without any problems.

System and installed packages

  • Windows 10
  • using a conda environment
  • package repository conda-forge
  • packages versions (selection):
jupyter_client            5.3.1                      py_0    conda-forge
jupyter_core              4.4.0                      py_0    conda-forge
nbsphinx                  0.4.2                      py_0    conda-forge
nbsphinx-link             1.2.0                    pypi_0    pypi
sphinx                    2.1.2                      py_0    conda-forge
sphinx_rtd_theme          0.4.3                      py_0    conda-forge
@mgeier
Copy link
Member

mgeier commented Aug 15, 2019

Hmmm ... error message says jupyter_client is missing ... but you seem to have it installed ...

I don't know what's going wrong here.

I normally install ipykernel, did you try that?

What happens if you execute your notebook directly with nbconvert (without involving nbsphinx)?

python3 -m nbconvert --execute <notebook_name>.ipynb

@euronion
Copy link
Author

Hi, thanks for making me feel a bit more sane (this kept me scratching my head yesterday) :)

  • Yep, ipykernel is also installed
>  conda list | findstr "ipykernel"
ipykernel                 5.1.2            py37h5ca1d4c_0    conda-forge
  • Executing the notebook directly as you suggest also works (providing the kernel_name since I am using a conda environment)
> python -m nbconvert --ExecutePreprocessor.kernel_name=python3 --execute <notebook_name>.ipynb
[NbConvertApp] Converting notebook <notebook_name>.ipynb to html
[NbConvertApp] Executing notebook with kernel: python3
...

I am quite content with not executing the notebooks at the moment:
This is not an important feature / matter for me.
Should I be the only one currently experiencing this, then we can just let the matter rest.

@mgeier
Copy link
Member

mgeier commented Aug 15, 2019

providing the kernel_name since I am using a conda environment

This seems to be the only difference, did you try this with nbsphinx as well?

nbsphinx_kernel_name = 'python3'

@euronion
Copy link
Author

Yes, I tried that as well: No change.

@mgeier
Copy link
Member

mgeier commented Aug 23, 2019

Is it possible that you have different versions of Python installed?
Or different environments?
And Sphinx and nbconvert use different versions (which have different packages available)?

How are you running Sphinx/nbsphinx?

Are you using python3 -m sphinx ...?

@euronion
Copy link
Author

euronion commented Aug 23, 2019

tl;dr: I found a solution which works.

Is it possible that you have different versions of Python installed?
Or different environments?

Yes

  • my systems default is 2.7 .
  • Additionally a conda base (with 3.7.1)
  • multiple conda environments (various Python versions)

I am using one of the conda environments for compiling the doc.
Both the conda base environment and the one I am using for compiling the doc have the jupyter_client installed.

And Sphinx and nbconvert use different versions (which have different packages available)?

How could I check?

My build method

How are you running Sphinx/nbsphinx?
Are you using python3 -m sphinx ...?

I haven't given this any thought:

  • it just "worked out of the box" (with the sphinx files craete from quickstart)
  • Using vscode as an editor + the rst extension
  • Using the rst-Preview causes causes sphinx to run and compile the documentation

This worked fine for me until now and was very convinient.
The problem somehow seems to be created by the commands issued here in the background.
(Which I have yet to figure out which they are).

Alternative build method

Following the direction of your questions I spend a few minutes on another build process.
Resulting in thie solution which works for me:

  • Setting nbsphinx_kernel_name in conf.py
  • using the quick-start make.bat from sphinx
  • Building the documentation using make.bat html

Caveat:
No problem with this approach, sadly less convinient (and I have pass on the Preview functionality from my editor).

@mgeier
Copy link
Member

mgeier commented Aug 25, 2019

I guess you'll have to find out which Python executable is used by the RST preview extension and how to install packages for it.

In case of doubt you should ask the makers of the RST preview.

How could I check?

I think the simplest way to check is to add some code to your conf.py file. Something like this would probably work:

import sys
print('My Python version:', sys.version)
print('My Python executable:', sys.executable)

However, if the terminal output is somehow swallowed by the RST extension, you might not see the relevant lines. In this case you could try to write the information to a temporary file and look at the file after running the preview.

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

No branches or pull requests

2 participants