No module named ipykernel_launcher
Asked Answered
L

8

22

I'm trying to register a pyenv-virtual env as a jupiter lab kernel on MacOs. I have this working on ubuntu but I'm running into issues on my MacBook.

I followed the instructions here which creates the following kernel spec file.

{
"argv": [
"/Users/david/.pyenv/versions/python36-tf2/bin/python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python (3.6.8 TF2.0)",
"language": "python"
}

I tested by running Users/david/.pyenv/versions/python36-tf2/bin/python -m ipykernel_launcher and it works fine.

But when I run jupiter lab (system python) then try and use the new kernel it aborts with log messages

/Users/david/.pyenv/versions/python36-tf20/bin/python: No module named ipykernel_launcher

Any ideas how to fix, the pyenv definitely can run ipykernel_launcher?

Lanti answered 9/8, 2019 at 2:0 Comment(1)
I'm having the same issue. The virtualenv can run ipykernel_launcher. kernelspec is giving me the correct path where the virtualenv is. Tried every solution given on github but none seems to workBlotch
T
3

Installing pip correctly is the answer

https://opensource.com/article/19/5/python-3-default-mac#what-to-do

install pip in the new directory, and from there- download jupyter-lab again.

Toothpick answered 2/11, 2020 at 4:11 Comment(1)
I think rather than pip this comment should say "install python3 as system python correctly" as I don't think the problem was pip itself. But certainly building python 3.7.8 via pyenv and then pyenv global 3.7.8 works so I'll mark this as the correct answer. BTW I installed 3.7.8 as 3.7.3 wouldn't build on Big Sur. Also had post BigSur issues with xcode (fixed with sudo rm -rf /Library/Developer/CommandLineTools then sudo xcode-select --install)Lanti
U
10

The error is due to the unavailability of the module named ipykernel_launcher. (reference)

Try this, this should work.

pip uninstall ipykernel # this may or may not be installed.
pip install ipykernel
Underwaist answered 1/10, 2021 at 4:47 Comment(1)
That definitely wasn't the problem, as I mentioned in my post I imported ipykernel to ensure it was installed. I'm not really sure what the problem was but it was related to pyenv and not loading the correct virtualenv rather than something as simple as a missing library.Lanti
P
3

I was facing the same issue some time ago. Un-installing and re-installing jupyter from your virtual environment using conda/pip may help.

Penurious answered 20/10, 2020 at 12:35 Comment(2)
I tried that a few times, also deleting and recreating the venv. I may try again - this was some time back but I've not used notebooks for a while so it's not really been an issue.Lanti
This worked for me. Problem was I had nuked my venv and rebuilt it at some point (after a Python upgrade), but neglected to reinstall ipykernel/jupyter into the venv.Rolanderolando
T
3

Installing pip correctly is the answer

https://opensource.com/article/19/5/python-3-default-mac#what-to-do

install pip in the new directory, and from there- download jupyter-lab again.

Toothpick answered 2/11, 2020 at 4:11 Comment(1)
I think rather than pip this comment should say "install python3 as system python correctly" as I don't think the problem was pip itself. But certainly building python 3.7.8 via pyenv and then pyenv global 3.7.8 works so I'll mark this as the correct answer. BTW I installed 3.7.8 as 3.7.3 wouldn't build on Big Sur. Also had post BigSur issues with xcode (fixed with sudo rm -rf /Library/Developer/CommandLineTools then sudo xcode-select --install)Lanti
C
2

I found uninstalling the version of Python then reinstalling it worked for me with no issues.

Chronology answered 16/3, 2021 at 20:25 Comment(1)
That could well have been the solution. In the end, it's been a long time (and an upgrade to BigSur) but certainly, there was some issue with my original system Python 3 installation which seems to be rectified by reinstallation one way or another.Lanti
B
1

Installing ipykernel (it was not installed in the first place) worked perfectly for me:

pip install ipykernel
Beadle answered 19/1, 2022 at 17:23 Comment(0)
M
0

I installed Jupyter Notebook on Windows 10 according to this article but got the same error. Reinstalling ipykernel won't work. I checked \Lib\site-packages and confirmed that the module is actually there. I tried to run jupyter notebook from site-packages and it worked. So I ended up creating a batch file:

CALL "[path to virtualenv]\Scripts\activate.bat"
cd "[path to virtualenv]\Lib\site-packages"
jupyter notebook
Modulate answered 21/3, 2022 at 2:36 Comment(0)
R
0

For me,

poetry remove ipykernel
poetry add ipykernel
poetry install

fixed the issue.

Rata answered 14/11, 2022 at 10:29 Comment(0)
C
0

I faced this issue with nix because I was doing this to run jupyterlab

nix shell nixpkgs#python312Packages.jupyterlab

And then running jupyter lab.

But it seems that python packages require a different way of running.

nix-shell -p "python312.withPackages (ps: with ps; [ jupyterlab ])"

Then run jupyter lab. Now it finds ipykernel_launcher.

Ref: https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/python.section.md#user-guide-user-guide

And https://github.com/NixOS/nixpkgs/issues/312487#issuecomment-2118501018

Cicada answered 19/5, 2024 at 4:3 Comment(1)
I know this question is tagged macos and virtualenv and got nothing to do with nix but I think it's still useful if only for a few nix beginners who make the same mistake and get the same error.Cicada

© 2022 - 2025 — McMap. All rights reserved.