简体   繁体   中英

Cannot run Jupyter notebooks due to nest_asyncio.py

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?

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

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

Apparently this error occurs for nest-asyncio=1.5.2 ( issue ). Upgrading to nest-asyncio=1.5.3 worked for me. You can run the following commands to uninstall the existing version and upgrade to 1.5.3 :

pip uninstall nest-asyncio
pip install nest-asyncio==1.5.3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM