17

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?

Remzouz
  • 157
  • 7
David Waterworth
  • 2,214
  • 1
  • 21
  • 41
  • 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 work – Remzouz May 26 '20 at 16:22

7 Answers7

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
Mohith7548
  • 1,282
  • 2
  • 16
  • 24
  • 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. – David Waterworth Oct 01 '21 at 05:41
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.

Ishank Saxena
  • 319
  • 2
  • 7
  • 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. – David Waterworth Oct 20 '20 at 21:38
  • 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. – SigmaX Jan 24 '22 at 19:35
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.

  • 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`) – David Waterworth Feb 17 '21 at 05:54
2

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

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Jordan
  • 84
  • 5
  • 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. – David Waterworth Mar 16 '21 at 20:57
1

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

pip install ipykernel
vvvvv
  • 25,404
  • 19
  • 49
  • 81
Blaze N
  • 11
  • 1
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
Weihui Guo
  • 3,669
  • 5
  • 34
  • 56
0

For me,

poetry remove ipykernel
poetry add ipykernel
poetry install

fixed the issue.

zabop
  • 6,750
  • 3
  • 39
  • 84