Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No module named ipykernel #1558

Closed
yutkin opened this issue Jun 20, 2016 · 20 comments
Closed

No module named ipykernel #1558

yutkin opened this issue Jun 20, 2016 · 20 comments

Comments

@yutkin
Copy link

yutkin commented Jun 20, 2016

I've installed jupyter via pip in virtualenv with python3.5. When I create new notebook I get an error:

[I 10:36:44.466 NotebookApp] Creating new notebook in
[I 10:36:46.139 NotebookApp] Kernel started: 48e51be7-f430-4adc-8bb1-83cc50953983
[W 10:36:46.180 NotebookApp] 404 GET /nbextensions/widgets/notebook/js/extension.js?v=20160620103640 (::1) 17.22ms referer=http://localhost:8888/notebooks/Untitled.ipynb?kernel_name=python3
/usr/local/opt/python3/bin/python3.5: No module named ipykernel
[I 10:36:49.061 NotebookApp] KernelRestarter: restarting kernel (1/5)
/usr/local/opt/python3/bin/python3.5: No module named ipykernel
[I 10:36:52.068 NotebookApp] KernelRestarter: restarting kernel (2/5)
/usr/local/opt/python3/bin/python3.5: No module named ipykernel
[I 10:36:55.104 NotebookApp] KernelRestarter: restarting kernel (3/5)
/usr/local/opt/python3/bin/python3.5: No module named ipykernel
[W 10:36:56.195 NotebookApp] Timeout waiting for kernel_info reply from 48e51be7-f430-4adc-8bb1-83cc50953983

How to fix this?

My pip list:

appnope (0.1.0)
backports.shutil-get-terminal-size (1.0.0)
decorator (4.0.10)
entrypoints (0.2.2)
gnureadline (6.3.3)
ipykernel (4.3.1)
ipython (4.2.0)
ipython-genutils (0.1.0)
ipywidgets (5.1.5)
Jinja2 (2.8)
jsonschema (2.5.1)
jupyter (1.0.0)
jupyter-client (4.3.0)
jupyter-console (4.1.1)
jupyter-core (4.1.0)
MarkupSafe (0.23)
mistune (0.7.2)
nbconvert (4.2.0)
nbformat (4.0.1)
notebook (4.2.1)
pexpect (4.1.0)
pickleshare (0.7.2)
pip (8.1.2)
ptyprocess (0.5.1)
Pygments (2.1.3)
pyzmq (15.2.0)
qtconsole (4.2.1)
setuptools (23.0.0)
simplegeneric (0.8.1)
terminado (0.6)
tornado (4.3)
traitlets (4.2.1)
wheel (0.29.0)
widgetsnbextension (1.2.3)

P.S. I'm using OS X 10.11.5

@yutkin yutkin closed this as completed Jun 20, 2016
@takluyver
Copy link
Member

Did you close the issue because you resolved the problem?

@yutkin
Copy link
Author

yutkin commented Jun 20, 2016

Yes, I've created kernel.json file with path to the virtualenv python.

@takluyver
Copy link
Member

OK, great.

@fonnesbeck
Copy link

I have the same issue here, but am unclear as to how it was fixed. To be clear, I need to manually create kernel.json file? All I did was to create an environment (Py3.5) and attempted to use it straight away after creation. Should this not be expected to work?

@fonnesbeck
Copy link

OK, I did not have ipykernel in my environment.yml. This seems to have fixed it for me.

@minrk minrk added this to the no action milestone Nov 23, 2016
@k1trd
Copy link

k1trd commented Apr 6, 2017

I installed Anaconda with py2.7. now i have the exact same issue but cant solve it, how can I created kernel.jason file with path to virtualenv??

@takluyver
Copy link
Member

@k1trd have a look at http://ipython.readthedocs.io/en/stable/install/kernel_install.html#kernels-for-different-environments

@k1trd
Copy link

k1trd commented Apr 12, 2017

thank you

@DaehanKim
Copy link

Similar case but not same, Simply installing ipykernel worked for me.

conda install ipykernel

@nikhilpriyatam
Copy link

I had the exact same issue. I used the following commands to fix this.

source activate <ANACONDA_ENVIRONMENT_NAME>
pip install ipykernel
python -m ipykernel install --user

@ChanaLii
Copy link

ChanaLii commented Sep 20, 2019

I got this error when I use the jupyter notebook.

[I 14:50:05.364 NotebookApp] Kernel started: 6b8ca55c-833a-4808-8493-6b51e5aa3e55
/root/anaconda3/bin/python: No module named ipykernel
[I 14:50:08.365 NotebookApp] KernelRestarter: restarting kernel (1/5)
/root/anaconda3/bin/python: No module named ipykernel
[I 14:50:11.376 NotebookApp] KernelRestarter: restarting kernel (2/5)
/root/anaconda3/bin/python: No module named ipykernel
[I 14:50:14.385 NotebookApp] KernelRestarter: restarting kernel (3/5)
/root/anaconda3/bin/python: No module named ipykernel
[W 14:50:15.386 NotebookApp] Timeout waiting for kernel_info reply from 6b8ca55c-833a-4808-8493-6b51e5aa3e55
[I 14:50:17.394 NotebookApp] KernelRestarter: restarting kernel (4/5)
WARNING:root:kernel 6b8ca55c-833a-4808-8493-6b51e5aa3e55 restarted
/root/anaconda3/bin/python: No module named ipykernel
[W 14:50:20.405 NotebookApp] KernelRestarter: restart failed
[W 14:50:20.406 NotebookApp] Kernel 6b8ca55c-833a-4808-8493-6b51e5aa3e55 died, removing from map.
ERROR:root:kernel 6b8ca55c-833a-4808-8493-6b51e5aa3e55 restarted failed!
[W 14:50:20.439 NotebookApp] Kernel deleted before session
[W 14:50:20.440 NotebookApp] 410 DELETE /api/sessions/ef5bafac-57ab-4a47-88db-eba6bd7dc0d5 (127.0.0.1) 3.30ms referer=http://localhost:8888/notebooks/Untitled.ipynb

The env already install ipykernel

(tf-3) [root@hadoop7 python_dep]# conda search ipykernel
Loading channels: done

Name Version Build Channel

ipykernel 4.0.3 py27_0 anaconda/pkgs/free
ipykernel 4.0.3 py34_0 anaconda/pkgs/free
ipykernel 4.0.3 py35_0 anaconda/pkgs/free
ipykernel 4.1.0 py27_0 anaconda/pkgs/free
ipykernel 4.1.0 py34_0 anaconda/pkgs/free
ipykernel 4.1.0 py35_0 anaconda/pkgs/free
ipykernel 4.1.1 py27_0 anaconda/pkgs/free
ipykernel 4.1.1 py34_0 anaconda/pkgs/free
ipykernel 4.1.1 py35_0 anaconda/pkgs/free
ipykernel 4.2.2 py27_0 anaconda/pkgs/free
ipykernel 4.2.2 py34_0 anaconda/pkgs/free
ipykernel 4.2.2 py35_0 anaconda/pkgs/free
ipykernel 4.3.1 py27_0 anaconda/pkgs/free
ipykernel 4.3.1 py34_0 anaconda/pkgs/free
ipykernel 4.3.1 py35_0 anaconda/pkgs/free
ipykernel 4.4.1 py27_0 anaconda/pkgs/free
ipykernel 4.4.1 py34_0 anaconda/pkgs/free
ipykernel 4.4.1 py35_0 anaconda/pkgs/free
ipykernel 4.5.0 py27_0 anaconda/pkgs/free
ipykernel 4.5.0 py34_0 anaconda/pkgs/free
ipykernel 4.5.0 py35_0 anaconda/pkgs/free
ipykernel 4.5.1 py27_0 anaconda/pkgs/free
ipykernel 4.5.1 py34_0 anaconda/pkgs/free
ipykernel 4.5.1 py35_0 anaconda/pkgs/free
ipykernel 4.5.2 py27_0 anaconda/pkgs/free
ipykernel 4.5.2 py34_0 anaconda/pkgs/free
ipykernel 4.5.2 py35_0 anaconda/pkgs/free
ipykernel 4.5.2 py36_0 anaconda/pkgs/free
ipykernel 4.6.0 py27_0 anaconda/pkgs/free
ipykernel 4.6.0 py35_0 anaconda/pkgs/free
ipykernel 4.6.0 py36_0 anaconda/pkgs/free
ipykernel 4.6.1 py27_0 anaconda/pkgs/free
ipykernel 4.6.1 py35_0 anaconda/pkgs/free
ipykernel 4.6.1 py36_0 anaconda/pkgs/free

How do I fix this problem?

@Akhi1
Copy link

Akhi1 commented Oct 30, 2019

I had the exact same issue. I used the following commands to fix this.

pip install ipykernel
python -m ipykernel install --user

Worked perfectly. Thank you @nikhilpriyatam

@bafflingscience
Copy link

Thanks @takluyver for the resource.
In the end, I used the same solution as @DaehanKim.
conda install ipykernel

@ebanner
Copy link

ebanner commented Jan 23, 2020

I'm stumped. I'm getting the following error.

/Users/edwardbanner/.pyenv/versions/my_env/bin/python: No module named ipykernel

However, I'm able to do the following.

$ /Users/edwardbanner/.pyenv/versions/my_env/bin/python
Python 3.6.9 (default, Jan 22 2020, 15:26:44) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.10.44.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ipykernel
>>> 

pyenv activate my_env && pip freeze shows me the ipykernel is installed.

ipykernel==5.1.3

My ~/Library/Jupyter/kernels/my_env/kernel.json looks right.

{
 "argv": [ "/Users/edwardbanner/.pyenv/versions/my_env/bin/python", "-m", "ipykernel", "-f", "{connection_file}"],
 "display_name": "my_env",
 "language": "python"
}

I'm even able to run the exact ipykernel command!

$ /Users/edwardbanner/.pyenv/versions/my_env/bin/python -m ipykernel
NOTE: When using the `ipython kernel` entry point, Ctrl-C will not work.

To exit, you will have to explicitly quit this process, by either sending
"quit" from a client, or using Ctrl-\ in UNIX-like environments.

To read more about this, see https://github.com/ipython/ipython/issues/2049


To connect another client to this kernel, use:
    --existing kernel-70354.json

It's just that when jupyter tries to run that exact command, it's hitting that error 🤷

@zoltansebestyen
Copy link

I think I've found the root cause, though not the solution yet: the python3.7 in the venv environment is symlinked to /usr/local/bin/python3.7, still they have different sys.path, see below:

local python3.7 works

➜  pandas-tutorial git:(master) ✗ source venv/bin/activate
(venv) ➜  pandas-tutorial git:(master) ✗ type python3.7          
python3.7 is /Users/zoltans/Work/homebanking/pandas-tutorial/venv/bin/python3.7
(venv) ➜  pandas-tutorial git:(master) ✗ python3.7                                                                                                              <<<
Python 3.7.7 (default, Mar 10 2020, 15:43:33) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/zoltans/Work/homebanking/pandas-tutorial/venv/lib/python3.7/site-packages']
>>> import ipykernel
>>> 

It's a link of /usr/local/bin/python3.7

(venv) ➜  pandas-tutorial git:(master) ✗ readlink /Users/zoltans/Work/homebanking/pandas-tutorial/venv/bin/python3.7
/usr/local/bin/python3.7

Running that python3.7 won't import the same path:

(venv) ➜  pandas-tutorial git:(master) ✗ /usr/local/bin/python3.7
Python 3.7.7 (default, Mar 10 2020, 15:43:33) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/zoltans/Library/Python/3.7/lib/python/site-packages', '/usr/local/lib/python3.7/site-packages']
>>> import ipykernel
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'ipykernel'
>>> 

@zoltansebestyen
Copy link

Ok, here it goes: I've had a previous - global - installation is jupyter and just switched to venv based install and because of that,
I've had the following kernels (local and global) and the second one was the default.
That bad definition, combined with python3.7 interpreter's path issue caused the 'No module ...' error for me.

# All kernel definitions
(venv) ➜  pandas-tutorial git:(master) ✗ mdfind -name kernel.json
zsh: correct 'kernel.json' to 'kernels.json' [nyae]? n
/Users/zoltans/Library/Jupyter/kernels/python3/kernel.json
/Users/zoltans/Library/Jupyter/kernels/jupyter3_python_3/kernel.json
/Users/zoltans/Work/homebanking/pandas-tutorial/venv/share/jupyter/kernels/python3/kernel.json
/Users/zoltans/Work/homebanking/pandas-tutorial/dev/share/jupyter/kernels/python3/kernel.json

# The default one to me, pointing to a not venv python binary
(venv) ➜  pandas-tutorial git:(master) ✗ cat /Users/zoltans/Library/Jupyter/kernels/jupyter3_python_3/kernel.json
{
 "argv": [
  "/usr/local/opt/python/bin/python3.7",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "jupyter3_Python_3",
 "language": "python"
}

Kudos to nteract/hydrogen#1824 for letting me know about jupyter kernelspec list --json

@JeffMou
Copy link

JeffMou commented Sep 1, 2020

I'm solved this problem by restart the cmd

@acdifran
Copy link

acdifran commented Sep 16, 2020

@ebanner I was having the exact same issue as you, trying to use a pyenv environment inside jupyter. Everything seemed fine from the python shell and I could even run the command manually like you did. I eventually found that if I started my notebook with my default kernel and checked "sys.path", it was listing some old version of python I had installed via hombrew and that was messing everything up and preventing my pyenv python versions from running jupyter. I uninstalled the brew version of python, removed any existing versions of jupyter, reinstall jupyter and now everything is working as expected.

@AIntosha
Copy link

ubuntu if

conda install ipykernel
python -m ipykernel install --user

doesn't work, then try to use
python3.7 -m ipykernel install --user

@bhrutledge
Copy link

Thanks @ebanner, @zoltansx, and @acdifran for the detailed write-ups. In my case, I did pip install jupyterlab in a virtual environment created using Python 3.8 from macOS Catalina (i.e /usr/bin/python3). Then, I installed a kernel spec from another virtual environment created using Python 3.6 from pyenv. Attempting to start a notebook with that kernel resulted in a No module named ipykernel_launcher from jupyter-lab.

I was able to resolve it by deleting the Python 3.8 virtual environment, creating a new one with Python 3.6 from pyenv, then installing and running jupyterlab from that virtual environment.

FWIW, I don't think it's necessary for the Python versions to be identical between the Jupyter virtual environment and the kernel virtual environment. For example, on another device, my Jupyter virtual environment is running Python 3.8, but it's from pyenv (i.e., not the macOS default), and that's able to run notebooks from the pyenv Python 3.6 virtual environment.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests