简体   繁体   中英

Multiple Kernels in Python Jupyter Notebook

I currently have Python 3 installed and want to install Python 2.7 as a second kernel in Jupyter notebook. I was able to install Python 2.7, however, when I change kernels in Jupyter notebook, I receive the following error in the Anaconda command prompt:

    [I 17:49:16.185 NotebookApp] Starting buffering for 069e4484-8d64-46e2-b62a-3588e46b4686:2857761af92f4e9387378c8162efbf40
[I 17:49:16.406 NotebookApp] Kernel shutdown: 069e4484-8d64-46e2-b62a-3588e46b4686
[I 17:49:16.453 NotebookApp] Kernel started: a9d7404d-02f1-4295-854d-0b11120cd3d2
Traceback (most recent call last):
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\ipykernel\__init__.py", line 2, in <module>
    from .connect import *
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\ipykernel\connect.py", line 18, in <module>
    import jupyter_client
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\jupyter_client\__init__.py", line 4, in <module>
    from .connect import *
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\jupyter_client\connect.py", line 24, in <module>
    import zmq
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\__init__.py", line 47, in <module>
    from zmq import backend
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\__init__.py", line 40, in <module>
    reraise(*exc_info)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\__init__.py", line 27, in <module>
    _ns = select_backend(first)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\select.py", line 28, in select_backend
    mod = __import__(name, fromlist=public_api)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\cython\__init__.py", line 6, in <module>
    from . import (constants, error, message, context,
ImportError: DLL load failed: The specified module could not be found.
[I 17:49:19.462 NotebookApp] KernelRestarter: restarting kernel (1/5), new random ports
Traceback (most recent call last):
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\ipykernel\__init__.py", line 2, in <module>
    from .connect import *
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\ipykernel\connect.py", line 18, in <module>
    import jupyter_client
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\jupyter_client\__init__.py", line 4, in <module>
    from .connect import *
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\jupyter_client\connect.py", line 24, in <module>
    import zmq
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\__init__.py", line 47, in <module>
    from zmq import backend
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\__init__.py", line 40, in <module>
    reraise(*exc_info)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\__init__.py", line 27, in <module>
    _ns = select_backend(first)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\select.py", line 28, in select_backend
    mod = __import__(name, fromlist=public_api)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\cython\__init__.py", line 6, in <module>
    from . import (constants, error, message, context,
ImportError: DLL load failed: The specified module could not be found.
[I 17:49:22.484 NotebookApp] KernelRestarter: restarting kernel (2/5), new random ports
Traceback (most recent call last):
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\ipykernel\__init__.py", line 2, in <module>
    from .connect import *
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\ipykernel\connect.py", line 18, in <module>
    import jupyter_client
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\jupyter_client\__init__.py", line 4, in <module>
    from .connect import *
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\jupyter_client\connect.py", line 24, in <module>
    import zmq
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\__init__.py", line 47, in <module>
    from zmq import backend
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\__init__.py", line 40, in <module>
    reraise(*exc_info)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\__init__.py", line 27, in <module>
    _ns = select_backend(first)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\select.py", line 28, in select_backend
    mod = __import__(name, fromlist=public_api)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\cython\__init__.py", line 6, in <module>
    from . import (constants, error, message, context,
ImportError: DLL load failed: The specified module could not be found.
[I 17:49:25.514 NotebookApp] KernelRestarter: restarting kernel (3/5), new random ports
Traceback (most recent call last):
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\ipykernel\__init__.py", line 2, in <module>
    from .connect import *
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\ipykernel\connect.py", line 18, in <module>
    import jupyter_client
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\jupyter_client\__init__.py", line 4, in <module>
    from .connect import *
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\jupyter_client\connect.py", line 24, in <module>
    import zmq
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\__init__.py", line 47, in <module>
    from zmq import backend
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\__init__.py", line 40, in <module>
    reraise(*exc_info)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\__init__.py", line 27, in <module>
    _ns = select_backend(first)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\select.py", line 28, in select_backend
    mod = __import__(name, fromlist=public_api)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\cython\__init__.py", line 6, in <module>
    from . import (constants, error, message, context,
ImportError: DLL load failed: The specified module could not be found.
[I 17:49:28.529 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports
Traceback (most recent call last):
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\ipykernel\__init__.py", line 2, in <module>
    from .connect import *
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\ipykernel\connect.py", line 18, in <module>
    import jupyter_client
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\jupyter_client\__init__.py", line 4, in <module>
    from .connect import *
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\jupyter_client\connect.py", line 24, in <module>
    import zmq
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\__init__.py", line 47, in <module>
    from zmq import backend
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\__init__.py", line 40, in <module>
    reraise(*exc_info)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\__init__.py", line 27, in <module>
    _ns = select_backend(first)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\select.py", line 28, in select_backend
    mod = __import__(name, fromlist=public_api)
  File "C:\Users\Nick Alexander\Anaconda3\envs\py27\lib\site-packages\zmq\backend\cython\__init__.py", line 6, in <module>
    from . import (constants, error, message, context,
ImportError: DLL load failed: The specified module could not be found.
[W 17:49:31.528 NotebookApp] KernelRestarter: restart failed
[W 17:49:31.528 NotebookApp] Kernel a9d7404d-02f1-4295-854d-0b11120cd3d2 died, removing from map.

All the python 2.7 installation files seem to be in the path specified by the error message. Thanks!

I'm not sure this solves your problem but try running

\path\to\your\install\of\python\python2.7 -m jupyter notebook

This will open jupyter in python2.7 hopefully

Do you have Anaconda installed?

With Anaconda you can easily create a new virtual environment with the desired python version:

conda create --name py27 python=2.7

will create a new environment with Python version 2.7.

conda create --name py37 python=3.7

will create a new environment with Python version 3.7.

This is the best way to use multiple Python releases on the same machine - in my opinion - furthermore you don't need to install any version of Python in your machine, Anaconda will do it for you.

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