Run_notebook & notebook2script issue in notebook vs command line

I noticed something odd about using and on the command line vs. in a notebook. I’m not 100% sure if this isn’t due to my env or not.

I can run from the command line only if I use a registered ipykernel in the target notebook. However, within a notebook I can only run if I am using an auto-generated kernel.

I’m using auto-generated ipykernels (I think with nb_conda?) – so any conda env you have will show up as a kernel, without requiring you to manually register each one with:

(envname) $ python -m ipykernel install --name "envname"

Now, if I set the kernel as the auto-gen’d one, I can’t run on command line because it can’t find conda-env-fastai-py, the name of the auto-gen’d kernel. This kind of makes sense, and from what I read seems like a current Jupyter limitation.

The confusing bit, is that I can’t run a cell containing

!python 01_matmul-Copy1.ipynb

in my 01_matmul-Copy1 notebook without using the auto-gen’d kernel. If I use my registered fastai kernel, I get:

Traceback (most recent call last):
  File "", line 3, in <module>
    import json,fire,re
ModuleNotFoundError: No module named 'fire'

My guess is that the #!/usr/bin/env python line in is pointing to my base Python (which doesn’t have fire), but when it’s run with the auto-gen’d kernel, something somewhere is ‘tricked’ into treating my fastai env as base Python, and thus: no errors.

NOTE: If I find a solution I’ll post here; the running solution is to use a registered kernel when running from the command line, and an nb_conda auto-gen’d kernel when running from a cell in a notebook.

Early command-line testing before I discovered the in-notebook failure case:

notebook : 00_exports-Copy1.ipynb

$ 00_exports-Copy1.ipynb
$ python 00_exports-Copy1.ipynb

env : Python [conda env:fastai]

  • — FAIL
  • — PASS

env : fastai

  • — PASS
  • — PASS

notebook : 01_matmul-Copy1.ipynb

env : fastai

  • — PASS
  • — PASS

I’m guessing you didn’t activated Jupyter virtualenv first

!python 01_matmul-Copy1.ipynb

run system python interpreter which is not virtualenv interpreter
I had this problem on windows basically you need to activate virtual env and inside it your code
are you using Windows ?

I’m on macOS, using conda for envs.

Sorry don’t know to much about MacOS


when you start terminal do you see name in (brackets) can you try run
conda activate
conda deactivate and run your script to check is it Virtual ENV problem

@Borz @Michal_w

Trying to make this run locally via anaconda with fast ai installed.

First I activate my fastai env

Blockquoteconda acitivate fastai

Then I CD into my directory with fast ai code.
There I try to run

Blockquotepython 00_exports.ipnyb

get the following error:

Traceback (most recent call last):
File “”, line 12, in
if name == ‘main’: fire.Fire(run_notebook)
File “C:\Users\c17999\AppData\Local\Continuum\anaconda3\envs\fastai\lib\site-packages\fire\”, line 138, in Fire
component_trace = _Fire(component, args, parsed_flag_args, context, name)
File “C:\Users\c17999\AppData\Local\Continuum\anaconda3\envs\fastai\lib\site-packages\fire\”, line 471, in _Fire
File “C:\Users\c17999\AppData\Local\Continuum\anaconda3\envs\fastai\lib\site-packages\fire\”, line 675, in CallAndUpdateTrace
component = fn(*varargs, **kwargs)
File “”, line 8, in run_notebook
nb =, as_version=nbformat.current_nbformat, encoding=‘utf-8’)
File "C:\Users\c17999\AppData\Local\Continuum\anaconda3\envs\fastai\lib\site-packages\nbformat_init
.py", line 141, in read
return reads(, as_version, **kwargs)
File “C:\Users\c17999\AppData\Local\Continuum\anaconda3\envs\fastai\lib\encodings\”, line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: ‘charmap’ codec can’t decode byte 0x9d in position 18436: character maps to

Looked around couldnt find anyone providing resolutions or facing same issues