Going fast! #DataquestChallenge Premium Annual Offer:
500 get 50% & the next 1000 get 40% off.
GET OFFER CODE

(Python) Newly installed kernel in Jupyter Notebook with Tensorflow giving a 'connection failed' error

Hello,

I’m new to Python and am trying to install Tensorflow. However, I’m running into a ‘connection failed’ error in the Jupyter Notebook.

I’ve used the following code to install tensorflow using the Anaconda Prompt.
conda info –-envs
conda create --name py3-TF2.0-Adm python=3.8
conda activate py3-TF2.0-Adm
pip install tensorflow
pip install --upgrade tensorflow
conda install nb conda_kernels
pip install ipykernel
python -m ipykernel install --user --name py3-TF2.0-Adm
conda deactivate
pip install ipykernel
conda install nb_conda_kernels

Is there anything wrong with this code?

This is part of the code in the prompt, should this be of help.
It starts with: ImportError: DLL load failed while importing win32api: Kan opgegeven procedure niet vinden.
And ends with:
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[I 21:03:45.465 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports
[IPKernelApp] ERROR | Failed to load connection file: ‘C:\Users\nicol\AppData\Roaming\jupyter\runtime\kernel-29beaf05-6778-41c7-9ca0-f764a579e0c4.json’
Traceback (most recent call last):
File “C:\Users\nicol\anaconda3\envs\py3-TF2.0-Adm\lib\site-packages\ipykernel\kernelapp.py”, line 257, in init_connection_file
self.load_connection_file()
File “C:\Users\nicol\anaconda3\envs\py3-TF2.0-Adm\lib\site-packages\jupyter_client\connect.py”, line 494, in load_connection_file
info = json.load(f)
File “C:\Users\nicol\anaconda3\envs\py3-TF2.0-Adm\lib\json_init_.py”, line 293, in load
return loads(fp.read(),
File “C:\Users\nicol\anaconda3\envs\py3-TF2.0-Adm\lib\json_init_.py”, line 357, in loads
return _default_decoder.decode(s)
File “C:\Users\nicol\anaconda3\envs\py3-TF2.0-Adm\lib\json\decoder.py”, line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “C:\Users\nicol\anaconda3\envs\py3-TF2.0-Adm\lib\json\decoder.py”, line 355, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[W 21:03:48.475 NotebookApp] KernelRestarter: restart failed
[W 21:03:48.475 NotebookApp] Kernel 29beaf05-6778-41c7-9ca0-f764a579e0c4 died, removing from map.
[W 21:04:33.471 NotebookApp] Timeout waiting for kernel_info reply from 29beaf05-6778-41c7-9ca0-f764a579e0c4
[E 21:04:33.472 NotebookApp] Error opening stream: HTTP 404: Not Found (Kernel does not exist: 29beaf05-6778-41c7-9ca0-f764a579e0c4)
[W 21:04:34.488 NotebookApp] 404 GET /api/kernels/29beaf05-6778-41c7-9ca0-f764a579e0c4/channels?session_id=27ffa31767684b1f87fd766cf78fda05 (::1): Kernel does not exist: 29beaf05-6778-41c7-9ca0-f764a579e0c4
[W 21:04:34.494 NotebookApp] 404 GET /api/kernels/29beaf05-6778-41c7-9ca0-f764a579e0c4/channels?session_id=27ffa31767684b1f87fd766cf78fda05 (::1) 6.980000ms referer=None
[W 21:04:36.503 NotebookApp] Replacing stale connection: 29beaf05-6778-41c7-9ca0-f764a579e0c4:27ffa31767684b1f87fd766cf78fda05

Kind regards,
Nicolas

Hi @NicolasDeKeyser

Is this for Windows? I have windows installed on my laptop so these steps worked for me (with python version 3):

1. to check the environments currently existing: 
conda info --envs

2. to create a environment for tensorflow:
conda create --name <environment-name> <language> = <language-version>
conda create --name py3-tf2.0 python = 3

3. to activate the environment created:
conda activate <environment-name>
conda activate py3-tf2.0

4. to install tensforflow:
conda install tensorflow

5. to upgrade tensorflow to latest version:
conda install --upgrade tensorflow

6. to install ipython kernels:
pip install ipykernel

7. to be able to use the new environment in Jupyter Notebook:
conda install -n base nb_conda_kernels
- this has to be run in base directory
- full permission are required for windows user, using which command is executed on the folder C:\ProgramData\Anaconda3

I found this stack overflow post for the error: python - How to fix “ImportError: DLL load failed” while importing win32api - Stack Overflow

Edit: If you were able to solve this, could you please share the workaround you applied. Thanks.