Notebook: Dead Jupyter Kernel with python3

Created on 17 Jan 2018  路  10Comments  路  Source: jupyter/notebook

I am trying to use jupyter notebook with python3. Then I added the kernel with

python3 -m pip install ipykernel
python3 -m ipykernel install --user

But when I start a notebook it shows a Dead kernel message, and the terminal shows

Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

If I choose python2 kernel it works well. I can run python command in console without any issue.

Most helpful comment

No, it shouldn't require PYTHONPATH or PYTHONHOME to be set.

What happens if you install the notebook with Python 3 (python3 -m pip install notebook) and launch a Python 3 kernel from a Python 3 server?

All 10 comments

How are you launching the notebook, and how did you install python3? I think that error must mean there's something wrong in the environment - it's an error that Python gives before it runs any of our code.

Hi @takluyver.
I just run the notebook with jupyter notebook (or jupyter-notebook, both have same result) and I installed python3 with sudo apt-get. But I get this error only with the notebook and python3 kernel. Actually, I am able to run python3 commands in console, as well as my scripts and they work well. I do:

$ python3
Python 3.4.2 (default, Oct  8 2014, 10:45:20) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> 

I also checked the notebook with python2 and works properly.

According with some posts I verified the kernelspecs such I get

"python3": {
  "resource_dir": "/usr/local/share/jupyter/kernels/python3", 
  "spec": {
    "interrupt_mode": "signal", 
    "display_name": "Python 3", 
    "env": {}, 
    "language": "python", 
    "argv": [
      "/usr/bin/python3", 
      "-m", 
      "ipykernel_launcher", 
      "-f", 
      "{connection_file}"
    ], 
    "metadata": {}
  }
}, 
"python2": {
  "resource_dir": "/opt/bitnami/python/share/jupyter/kernels/python2", 
  "spec": {
    "interrupt_mode": "signal", 
    "display_name": "Python 2", 
    "env": {}, 
    "language": "python", 
    "argv": [
      "python", 
      "-m", 
      "ipykernel_launcher", 
      "-f", 
      "{connection_file}"
    ], 
    "metadata": {}
  }
}

I am not sure what is the issue here.
Does it depend on PYTHONPATH or PYTHONHOME? When I use echo for them, both are empty

No, it shouldn't require PYTHONPATH or PYTHONHOME to be set.

What happens if you install the notebook with Python 3 (python3 -m pip install notebook) and launch a Python 3 kernel from a Python 3 server?

If I run python3 -m pip install notebook it shows requirement already satisfied as follow

Requirement already satisfied: notebook in /usr/local/lib/python3.4/dist-packages
Requirement already satisfied: terminado>=0.8.1 in /usr/local/lib/python3.4/dist-packages (from notebook)
Requirement already satisfied: jupyter-client>=5.2.0 in /usr/local/lib/python3.4/dist-packages (from notebook)
Requirement already satisfied: tornado>=4 in /usr/local/lib/python3.4/dist-packages (from notebook)
Requirement already satisfied: Send2Trash in /usr/local/lib/python3.4/dist-packages (from notebook)
Requirement already satisfied: ipython-genutils in /usr/local/lib/python3.4/dist-packages (from notebook)
Requirement already satisfied: ipykernel in /usr/local/lib/python3.4/dist-packages (from notebook)
Requirement already satisfied: jupyter-core>=4.4.0 in /usr/local/lib/python3.4/dist-packages (from notebook)
Requirement already satisfied: nbformat in /usr/local/lib/python3.4/dist-packages (from notebook)
Requirement already satisfied: jinja2 in /usr/local/lib/python3.4/dist-packages (from notebook)
Requirement already satisfied: nbconvert in /usr/local/lib/python3.4/dist-packages (from notebook)
Requirement already satisfied: traitlets>=4.2.1 in /usr/local/lib/python3.4/dist-packages (from notebook)
Requirement already satisfied: ptyprocess; os_name != "nt" in /usr/local/lib/python3.4/dist-packages (from terminado>=0.8.1->notebook)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.4/dist-packages (from jupyter-client>=5.2.0->notebook)
Requirement already satisfied: pyzmq>=13 in /usr/local/lib/python3.4/dist-packages (from jupyter-client>=5.2.0->notebook)
Requirement already satisfied: backports_abc>=0.4 in /usr/local/lib/python3.4/dist-packages (from tornado>=4->no
tebook)
Requirement already satisfied: ipython>=4.0.0 in /usr/local/lib/python3.4/dist-packages (from ipykernel->noteboo
k)
Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in /usr/local/lib/python3.4/dist-packages (from nbformat-
>notebook)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.4/dist-packages (from jinja2->notebook
)
Requirement already satisfied: entrypoints>=0.2.2 in /usr/local/lib/python3.4/dist-packages (from nbconvert->not
ebook)
Requirement already satisfied: pandocfilters>=1.4.1 in /usr/local/lib/python3.4/dist-packages (from nbconvert->n
otebook)
Requirement already satisfied: testpath in /usr/local/lib/python3.4/dist-packages (from nbconvert->notebook)
Requirement already satisfied: bleach in /usr/local/lib/python3.4/dist-packages (from nbconvert->notebook)
Requirement already satisfied: pygments in /usr/local/lib/python3.4/dist-packages (from nbconvert->notebook)
Requirement already satisfied: mistune>=0.7.4 in /usr/local/lib/python3.4/dist-packages (from nbconvert->noteboo
k)
Requirement already satisfied: six in /usr/local/lib/python3.4/dist-packages (from traitlets>=4.2.1->notebook)
Requirement already satisfied: decorator in /usr/local/lib/python3.4/dist-packages (from traitlets>=4.2.1->noteb
ook)
Requirement already satisfied: pickleshare in /usr/local/lib/python3.4/dist-packages (from ipython>=4.0.0->ipyke
rnel->notebook)
Requirement already satisfied: typing; python_version <= "3.4" in /usr/local/lib/python3.4/dist-packages (from i
python>=4.0.0->ipykernel->notebook)
Requirement already satisfied: setuptools>=18.5 in /usr/local/lib/python3.4/dist-packages (from ipython>=4.0.0->
ipykernel->notebook)
Requirement already satisfied: simplegeneric>0.8 in /usr/local/lib/python3.4/dist-packages (from ipython>=4.0.0-
>ipykernel->notebook)
Requirement already satisfied: pexpect; sys_platform != "win32" in /usr/local/lib/python3.4/dist-packages (from 
ipython>=4.0.0->ipykernel->notebook)
Requirement already satisfied: jedi>=0.10 in /usr/local/lib/python3.4/dist-packages (from ipython>=4.0.0->ipyker
nel->notebook)
Requirement already satisfied: prompt-toolkit<2.0.0,>=1.0.4 in /usr/local/lib/python3.4/dist-packages (from ipyt
hon>=4.0.0->ipykernel->notebook)
Requirement already satisfied: html5lib!=1.0b1,!=1.0b2,!=1.0b3,!=1.0b4,!=1.0b5,!=1.0b6,!=1.0b7,!=1.0b8,>=0.99999
999pre in /usr/local/lib/python3.4/dist-packages (from bleach->nbconvert->notebook)
Requirement already satisfied: parso==0.1.1 in /usr/local/lib/python3.4/dist-packages (from jedi>=0.10->ipython>
=4.0.0->ipykernel->notebook)
Requirement already satisfied: wcwidth in /usr/local/lib/python3.4/dist-packages (from prompt-toolkit<2.0.0,>=1.
0.4->ipython>=4.0.0->ipykernel->notebook)
Requirement already satisfied: webencodings in /usr/local/lib/python3.4/dist-packages (from html5lib!=1.0b1,!=1.
0b2,!=1.0b3,!=1.0b4,!=1.0b5,!=1.0b6,!=1.0b7,!=1.0b8,>=0.99999999pre->bleach->nbconvert->notebook)

How do I launch a Python 3 kernel from a Python 3 server?

How do I launch a Python 3 kernel from a Python 3 server?

You need to launch jupyter that is in your python3 directory.
Something like that: /usr/local/lib/python3.4/bin/jupyter notebook

@OrangeBot,
My /usr/local/lib/python3.4 doesn't have bin directory, it only has dist-packages. Is it ok?
Here, I do python3 /usr/local/lib/python3.4/dist-packages/jupyter.py but it shows jupyter.py: error: one of the arguments --version subcommand --config-dir --data-dir --runtime-dir --paths is required. Which path should I define?
I tried --paths=/home/jcgarciaca/models/research/object_detection and --paths=/home/jcgarciaca/models/research/object_detection/object_detection_tutorial.ipynb but they show jupyter.py: error: argument --paths: ignored explicit argument '/home/jcgarciaca/models/research/object_detection'.

Yes, the bin folder will be /usr/local/bin and it's shared between Python 2 and 3 (and all sorts of other things). You can launch the notebook with a specific python version by running python3 -m notebook

Thank you @takluyver, with python3 -m notebook I am able to run my notebook perfectly with python3

OK, that's good. I'm still puzzled why it had the problem with encodings when you launched it with Python 2, though.

My host is in Ubuntu 18.04, Python 3.6.6. Then, I use pip3 install --user notebook to solve the problem. The key lost wheel is prompt_toolkit-2.0.6-py3-none-any.whl.
The installation requirement is `pip3 install --user notebook

Collecting notebook
Using cached https://files.pythonhosted.org/packages/44/16/9f108b675828c4117cfe72d8d0f97094163c40584e40c46ec48a1e862693/notebook-5.7.0-py2.py3-none-any.whl
Collecting nbconvert (from notebook)
Using cached https://files.pythonhosted.org/packages/b5/bb/94c493051d60e5b9c0f7f9a368b324201818c1b1c4cae85d1e49a41846c7/nbconvert-5.4.0-py2.py3-none-any.whl
Collecting pyzmq>=17 (from notebook)
Using cached https://files.pythonhosted.org/packages/48/93/59592cb294761aaa40589b544eaa5175446d687ff95beeeb666de60f3274/pyzmq-17.1.2-cp36-cp36m-manylinux1_x86_64.whl
Collecting nbformat (from notebook)
Using cached https://files.pythonhosted.org/packages/da/27/9a654d2b6cc1eaa517d1c5a4405166c7f6d72f04f6e7eea41855fe808a46/nbformat-4.4.0-py2.py3-none-any.whl
Collecting jinja2 (from notebook)
Using cached https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl
Collecting prometheus-client (from notebook)
Collecting terminado>=0.8.1 (from notebook)
Using cached https://files.pythonhosted.org/packages/2e/20/a26211a24425923d46e1213b376a6ee60dc30bcdf1b0c345e2c3769deb1c/terminado-0.8.1-py2.py3-none-any.whl
Collecting jupyter-core>=4.4.0 (from notebook)
Using cached https://files.pythonhosted.org/packages/1d/44/065d2d7bae7bebc06f1dd70d23c36da8c50c0f08b4236716743d706762a8/jupyter_core-4.4.0-py2.py3-none-any.whl
Collecting jupyter-client>=5.2.0 (from notebook)
Using cached https://files.pythonhosted.org/packages/94/dd/fe6c4d683b09eb05342bd2816b7779663f71762b4fa9c2d5203d35d17354/jupyter_client-5.2.3-py2.py3-none-any.whl
Collecting ipython-genutils (from notebook)
Using cached https://files.pythonhosted.org/packages/fa/bc/9bd3b5c2b4774d5f33b2d544f1460be9df7df2fe42f352135381c347c69a/ipython_genutils-0.2.0-py2.py3-none-any.whl
Collecting Send2Trash (from notebook)
Using cached https://files.pythonhosted.org/packages/49/46/c3dc27481d1cc57b9385aff41c474ceb7714f7935b1247194adae45db714/Send2Trash-1.5.0-py3-none-any.whl
Collecting traitlets>=4.2.1 (from notebook)
Using cached https://files.pythonhosted.org/packages/93/d6/abcb22de61d78e2fc3959c964628a5771e47e7cc60d53e9342e21ed6cc9a/traitlets-4.3.2-py2.py3-none-any.whl
Collecting ipykernel (from notebook)
Using cached https://files.pythonhosted.org/packages/d8/b0/f0be5c5ab335196f5cce96e5b889a4fcf5bfe462eb0acc05cd7e2caf65eb/ipykernel-5.1.0-py3-none-any.whl
Collecting tornado>=4 (from notebook)
Collecting pandocfilters>=1.4.1 (from nbconvert->notebook)
Collecting defusedxml (from nbconvert->notebook)
Using cached https://files.pythonhosted.org/packages/87/1c/17f3e3935a913dfe2a5ca85fa5ccbef366bfd82eb318b1f75dadbf0affca/defusedxml-0.5.0-py2.py3-none-any.whl
Collecting bleach (from nbconvert->notebook)
Using cached https://files.pythonhosted.org/packages/d4/0d/4696373c3b714f6022d668fbab619690a42050dbeacede6d10ed97fbd3e2/bleach-3.0.2-py2.py3-none-any.whl
Collecting testpath (from nbconvert->notebook)
Using cached https://files.pythonhosted.org/packages/be/a4/162f9ebb6489421fe46dcca2ae420369edfee4b563c668d93cb4605d12ba/testpath-0.4.2-py2.py3-none-any.whl
Collecting mistune>=0.8.1 (from nbconvert->notebook)
Using cached https://files.pythonhosted.org/packages/09/ec/4b43dae793655b7d8a25f76119624350b4d65eb663459eb9603d7f1f0345/mistune-0.8.4-py2.py3-none-any.whl
Collecting pygments (from nbconvert->notebook)
Using cached https://files.pythonhosted.org/packages/02/ee/b6e02dc6529e82b75bb06823ff7d005b141037cb1416b10c6f00fc419dca/Pygments-2.2.0-py2.py3-none-any.whl
Collecting entrypoints>=0.2.2 (from nbconvert->notebook)
Using cached https://files.pythonhosted.org/packages/cc/8b/4eefa9b47f1910b3d2081da67726b066e379b04ca897acfe9f92bac56147/entrypoints-0.2.3-py2.py3-none-any.whl
Collecting jsonschema!=2.5.0,>=2.4 (from nbformat->notebook)
Using cached https://files.pythonhosted.org/packages/77/de/47e35a97b2b05c2fadbec67d44cfcdcd09b8086951b331d82de90d2912da/jsonschema-2.6.0-py2.py3-none-any.whl
Collecting MarkupSafe>=0.23 (from jinja2->notebook)
Collecting ptyprocess; os_name != "nt" (from terminado>=0.8.1->notebook)
Using cached https://files.pythonhosted.org/packages/d1/29/605c2cc68a9992d18dada28206eeada56ea4bd07a239669da41674648b6f/ptyprocess-0.6.0-py2.py3-none-any.whl
Collecting python-dateutil>=2.1 (from jupyter-client>=5.2.0->notebook)
Using cached https://files.pythonhosted.org/packages/cf/f5/af2b09c957ace60dcfac112b669c45c8c97e32f94aa8b56da4c6d1682825/python_dateutil-2.7.3-py2.py3-none-any.whl
Collecting six (from traitlets>=4.2.1->notebook)
Using cached https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Collecting decorator (from traitlets>=4.2.1->notebook)
Using cached https://files.pythonhosted.org/packages/bc/bb/a24838832ba35baf52f32ab1a49b906b5f82fb7c76b2f6a7e35e140bac30/decorator-4.3.0-py2.py3-none-any.whl
Collecting ipython>=5.0.0 (from ipykernel->notebook)
Using cached https://files.pythonhosted.org/packages/a0/27/29d66ed395a5c2c3a912332d446a54e2bc3277c36b0bbd22bc71623e0193/ipython-7.0.1-py3-none-any.whl
Collecting webencodings (from bleach->nbconvert->notebook)
Using cached https://files.pythonhosted.org/packages/f4/24/2a3e3df732393fed8b3ebf2ec078f05546de641fe1b667ee316ec1dcf3b7/webencodings-0.5.1-py2.py3-none-any.whl
Collecting pickleshare (from ipython>=5.0.0->ipykernel->notebook)
Using cached https://files.pythonhosted.org/packages/9a/41/220f49aaea88bc6fa6cba8d05ecf24676326156c23b991e80b3f2fc24c77/pickleshare-0.7.5-py2.py3-none-any.whl
Collecting setuptools>=18.5 (from ipython>=5.0.0->ipykernel->notebook)
Using cached https://files.pythonhosted.org/packages/96/06/c8ee69628191285ddddffb277bd5abdf769166e7a14b867c2a172f0175b1/setuptools-40.4.3-py2.py3-none-any.whl
Collecting prompt-toolkit<2.1.0,>=2.0.0 (from ipython>=5.0.0->ipykernel->notebook)
Downloading https://files.pythonhosted.org/packages/06/6f/03f10d2206e34a81934b10fb43975a29028e0fe2ae330f9f000bbc0780b7/prompt_toolkit-2.0.6-py3-none-any.whl (336kB)
100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 337kB 25kB/s
Collecting simplegeneric>0.8 (from ipython>=5.0.0->ipykernel->notebook)
Collecting pexpect; sys_platform != "win32" (from ipython>=5.0.0->ipykernel->notebook)
Using cached https://files.pythonhosted.org/packages/89/e6/b5a1de8b0cc4e07ca1b305a4fcc3f9806025c1b651ea302646341222f88b/pexpect-4.6.0-py2.py3-none-any.whl
Collecting jedi>=0.10 (from ipython>=5.0.0->ipykernel->notebook)
Using cached https://files.pythonhosted.org/packages/7a/1a/9bd24a185873b998611c2d8d4fb15cd5e8a879ead36355df7ee53e9111bf/jedi-0.13.1-py2.py3-none-any.whl
Collecting backcall (from ipython>=5.0.0->ipykernel->notebook)
Collecting wcwidth (from prompt-toolkit<2.1.0,>=2.0.0->ipython>=5.0.0->ipykernel->notebook)
Using cached https://files.pythonhosted.org/packages/7e/9f/526a6947247599b084ee5232e4f9190a38f398d7300d866af3ab571a5bfe/wcwidth-0.1.7-py2.py3-none-any.whl
Collecting parso>=0.3.0 (from jedi>=0.10->ipython>=5.0.0->ipykernel->notebook)
Using cached https://files.pythonhosted.org/packages/09/51/9c48a46334be50c13d25a3afe55fa05c445699304c5ad32619de953a2305/parso-0.3.1-py2.py3-none-any.whl
Installing collected packages: ipython-genutils, six, decorator, traitlets, jupyter-core, pandocfilters, MarkupSafe, jinja2, defusedxml, webencodings, bleach, jsonschema, nbformat, testpath, mistune, pygments, entrypoints, nbconvert, pyzmq, prometheus-client, ptyprocess, tornado, terminado, python-dateutil, jupyter-client, Send2Trash, pickleshare, setuptools, wcwidth, prompt-toolkit, simplegeneric, pexpect, parso, jedi, backcall, ipython, ipykernel, notebook
Successfully installed MarkupSafe-1.0 Send2Trash-1.5.0 backcall-0.1.0 bleach-3.0.2 decorator-4.3.0 defusedxml-0.5.0 entrypoints-0.2.3 ipykernel-5.1.0 ipython-7.0.1 ipython-genutils-0.2.0 jedi-0.13.1 jinja2-2.10 jsonschema-2.6.0 jupyter-client-5.2.3 jupyter-core-4.4.0 mistune-0.8.4 nbconvert-5.4.0 nbformat-4.4.0 notebook-5.7.0 pandocfilters-1.4.2 parso-0.3.1 pexpect-4.6.0 pickleshare-0.7.5 prometheus-client-0.4.2 prompt-toolkit-2.0.6 ptyprocess-0.6.0 pygments-2.2.0 python-dateutil-2.7.3 pyzmq-17.1.2 setuptools-40.4.3 simplegeneric-0.8.1 six-1.11.0 terminado-0.8.1 testpath-0.4.2 tornado-5.1.1 traitlets-4.3.2 wcwidth-0.1.7 webencodings-0.5.1
`

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fonnesbeck picture fonnesbeck  路  3Comments

itoed picture itoed  路  3Comments

pylang picture pylang  路  3Comments

ehossain1982 picture ehossain1982  路  3Comments

cmesro picture cmesro  路  3Comments