KernelRestarter: restart failed - python

Jupyter notebook was installed with conda.
When notebook file is run, I have this "KernelRestarter: restart failed" error.
All error messages are as follows.
KernelRestarter: restarting kernel (4/5), new random ports
Traceback (most recent call last):
File "/home/itc/anaconda3/envs/fastai/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/itc/anaconda3/envs/fastai/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/itc/anaconda3/envs/fastai/lib/python3.6/site-packages/ipykernel_launcher.py", line 15, in <module>
from ipykernel import kernelapp as app
File "/home/itc/anaconda3/envs/fastai/lib/python3.6/site-packages/ipykernel/__init__.py", line 2, in <module>
from .connect import *
File "/home/itc/anaconda3/envs/fastai/lib/python3.6/site-packages/ipykernel/connect.py", line 13, in <module>
from IPython.core.profiledir import ProfileDir
File "/home/itc/anaconda3/envs/fastai/lib/python3.6/site-packages/IPython/__init__.py", line 49, in <module>
from .terminal.embed import embed
File "/home/itc/anaconda3/envs/fastai/lib/python3.6/site-packages/IPython/terminal/embed.py", line 18, in <module>
from IPython.terminal.interactiveshell import TerminalInteractiveShell
File "/home/itc/anaconda3/envs/fastai/lib/python3.6/site-packages/IPython/terminal/interactiveshell.py", line 20, in <module>
from prompt_toolkit.shortcuts import create_prompt_application, create_eventloop, create_prompt_layout, create_output
ImportError: cannot import name 'create_prompt_application'

Looking at the same problem as me. The ipykernel of my virtual environment cannot be started because of the wrong version of the component.
now fixed it.
pip3 install -U ipykernel

Related

vscode failed to start the kernel with numpy trouble

Here I get an error when I run script with Jupyter notebook and I try many approaches to solve it, but not succesful.
When I followed Failed to start the kernel on jupyter notebook to configue my jupyter file, but inefficient. And then I followed Failed to start the Kernel - Jupyter in VS Code, Jupyter - failed to start the kernel and vscode jupyter failed to start kernel aslo inefficient. Indeed, I am troubled by this question two days and I can't tolerate this. Who can help me?
here is a piuture about this question reminder information
Failed to start the Kernel.
Traceback (most recent call last):
File "/home/bio_kang/software/anaconda3/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/home/bio_kang/software/anaconda3/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/bio_kang/software/anaconda3/lib/python3.9/site-packages/ipykernel_launcher.py", line 15, in <module>
from ipykernel import kernelapp as app
File "/home/bio_kang/software/anaconda3/lib/python3.9/site-packages/ipykernel/__init__.py", line 2, in <module>
from .connect import *
File "/home/bio_kang/software/anaconda3/lib/python3.9/site-packages/ipykernel/connect.py", line 10, in <module>
import jupyter_client
File "/home/bio_kang/software/anaconda3/lib/python3.9/site-packages/jupyter_client/__init__.py", line 4, in <module>
from .connect import *
File "/home/bio_kang/software/anaconda3/lib/python3.9/site-packages/jupyter_client/connect.py", line 16, in <module>
import tempfile
File "/home/bio_kang/software/anaconda3/lib/python3.9/tempfile.py", line 45, in <module>
from random import Random as _Random
File "/home/bio_kang/Learning/Python/random.py", line 2, in <module>
import pandas as pd
File "/home/bio_kang/software/anaconda3/lib/python3.9/site-packages/pandas/__init__.py", line 16, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy: cannot import name SystemRandom.
View Jupyter log for further details.

Error message about 'libsqlite3' when activate environment in jupyter Notebook

I try to activate my env to Jupyter notebook by using:
python -m ipykernel install --user --name native --display-name "python-gpu"
But error message:
Traceback (most recent call last):
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/site-packages/ipykernel/__main__.py", line 2, in <module>
from ipykernel import kernelapp as app
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/site-packages/ipykernel/kernelapp.py", line 18, in <module>
from IPython.core.application import (
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/site-packages/IPython/__init__.py", line 53, in <module>
from .terminal.embed import embed
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/site-packages/IPython/terminal/embed.py", line 15, in <module>
from IPython.core.interactiveshell import DummyMod, InteractiveShell
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 73, in <module>
from IPython.core.history import HistoryManager
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/site-packages/IPython/core/history.py", line 11, in <module>
import sqlite3
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/sqlite3/__init__.py", line 57, in <module>
from sqlite3.dbapi2 import *
File "/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: dlopen(/Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/lib-dynload/_sqlite3.cpython-310-darwin.so, 0x0002): Symbol not found: _sqlite3_enable_load_extension
Referenced from: /Users/nianhua/opt/anaconda3/envs/native/lib/python3.10/lib-dynload/_sqlite3.cpython-310-darwin.so
Expected in: /usr/lib/libsqlite3.dylib
It seems like something is wrong with my libsqlite3, but it goes well in my terminal.
My laptop is a Macbook pro with M1Pro. And I'm building an arm64 python environment in M1 version Anaconda.
Does anyone know how I can get around this?
I had the same problem and I solved by installing a newer version:
mamba install sqlite=3.40.0
always checking that the new library is coming from conda-forge/osx-arm64.

Python, pip not working, but can't install pip

I've cloned a project and so when trying to install the packages in the scripts, I get the following error when trying to install from pycharm:
proposed solution:
Try to run this command from the system terminal. Make sure that you use the correct version of 'pip' installed for your Python interpreter located at '/home/yovel/PycharmProjects/Triangulation-Calculator/venv/bin/python'.
Error: Traceback (most recent call last):
File "/snap/pycharm-community/179/plugins/python-ce/helpers/packaging_tool.py", line 73, in run_pip
runpy.run_module(module_name, run_name='__main__', alter_sys=True)
File "/usr/lib/python3.8/runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib/python3.8/runpy.py", line 95, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/lib/python3.8/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/lib/python3/dist-packages/pip/__main__.py", line 16, in <module>
from pip._internal import main as _main # isort:skip # noqa
File "/usr/lib/python3/dist-packages/pip/_internal/__init__.py", line 40, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
from pip._internal.cli import cmdoptions
File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 18, in <module>
from pip._internal.models.format_control import FormatControl
File "/usr/lib/python3/dist-packages/pip/_internal/models/format_control.py", line 1, in <module>
from pip._vendor.packaging.utils import canonicalize_name
ModuleNotFoundError: No module named 'pip._vendor.packaging'
But when I run it from the terminal it successfully installs the package.
pip3 install pandas
...
Successfully installed pandas-1.0.1 python-dateutil-2.8.1 pytz-2019.3
But in pycharm I can't use it:
I tried updating venv and pip but it won't work.
And I should mention that it is not the original interpreter as the original's version was python 3.6.

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.

I'm getting ModuleNotFoundError: No module named _socket on ubuntu 18.04

I installed Anaconda3 on ubuntu and changed the path to ~/anaconda/bin in .bashrc file then I'm trying to install keras It's throwing this error.
hemanth#specter:~$ python3 -m pip install keras
Traceback (most recent call last):
File "/home/hemanth/anaconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/hemanth/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/hemanth/anaconda3/lib/python3.7/site-packages/pip/__main__.py", line 16, in <module>
from pip._internal import main as _main # isort:skip # noqa
File "/home/hemanth/anaconda3/lib/python3.7/site-packages/pip/_internal/__init__.py", line 19, in <module>
from pip._vendor.urllib3.exceptions import DependencyWarning
File "/home/hemanth/anaconda3/lib/python3.7/site-packages/pip/_vendor/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/home/hemanth/anaconda3/lib/python3.7/site-packages/pip/_vendor/urllib3/connectionpool.py", line 7, in <module>
from socket import error as SocketError, timeout as SocketTimeout
File "/home/hemanth/anaconda3/lib/python3.7/socket.py", line 49, in <module>
import _socket
ModuleNotFoundError: No module named '_socket'
I tried this command and it is working fine.
however, try to install socket using pip install sockets and then again try installing keras.

Categories