Home > OS >  Cannot run Jupyter notebooks due to nest_asyncio.py
Cannot run Jupyter notebooks due to nest_asyncio.py

Time:12-02

I am using Python 3.9.9 via pyenv on a Mac with an Intel chip. I installed Jupyter using pip install juypter. When I run which jupyter I get the response /Users/<username>/.pyenv/shims/jupyter, so Jupyter has installed. However, when I run jupyter notebook I get the following error:

Traceback (most recent call last):
  File "/Users/<username>/.pyenv/versions/3.9.9/bin/jupyter-notebook", line 8, in <module>
    sys.exit(main())
  File "/Users/<username>/.pyenv/versions/3.9.9/lib/python3.9/site-packages/jupyter_core/application.py", line 264, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/Users/<username>/.pyenv/versions/3.9.9/lib/python3.9/site-packages/traitlets/config/application.py", line 845, in launch_instance
    app.initialize(argv)
  File "/Users/<username>/.pyenv/versions/3.9.9/lib/python3.9/site-packages/traitlets/config/application.py", line 88, in inner
    return method(app, *args, **kwargs)
  File "/Users/<username>/.pyenv/versions/3.9.9/lib/python3.9/site-packages/notebook/notebookapp.py", line 2141, in initialize
    self._init_asyncio_patch()
  File "/Users/<username>/.pyenv/versions/3.9.9/lib/python3.9/site-packages/notebook/notebookapp.py", line 2117, in _init_asyncio_patch
    nest_asyncio.apply()
  File "/Users/<username>/.pyenv/versions/3.9.9/lib/python3.9/site-packages/nest_asyncio.py", line 14, in apply
    raise ValueError('Can\'t patch loop of type %s' % type(loop))
ValueError: Can't patch loop of type <class 'NoneType'>

I have never seen this error before and my search for a solution has been fruitless. Any ideas?

CodePudding user response:

faced similar issues and solved using:

pip3 install --upgrade pip 
pip3 install jupyter

maybe in your case you should use pip3.9

you can check the match of pip and python with

python --version
python -m pip --version

CodePudding user response:

Seens that it is a problem with jupyter and python 3.9:

https://github.com/jupyter/notebook/issues/5912

One possible solution is:

    • conda create -n py39 python=3.9
    • pip3 install --upgrade pip
    • pip3 install jupyter
    • source activate py39
    • Run jupyter-notebook

also, this issue contains mac os specific solution:

https://github.com/jupyter/notebook/issues/5872

  • Related