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?

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 work
    – Remzouz
    May 26, 2020 at 16:22

7 Answers 7

9

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
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. Oct 1, 2021 at 5:41
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.

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) Feb 17, 2021 at 5:54
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.

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. Oct 20, 2020 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, 2022 at 19:35
2

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

1
  • 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. Mar 16, 2021 at 20:57
1

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

pip install ipykernel
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
0

For me,

poetry remove ipykernel
poetry add ipykernel
poetry install

fixed the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.