🏋️♀️ When it comes to running JupyterLab & JupyterNotebooks, the install is pretty hefty, with quite a few dependencies.
🦉 To avoid the travails of picking through a messy base install of Python on your dev machine, it is wise to always use a virtual environment.
👍 Thus running JupyterLab in a virtual environment is a good idea.
Here's how using macOS.
- Navigate to a suitable directory in which want to work, or make a new one.
- Copy the Jupyter Notebook that you want to work on to this directory.
Create a virtual environment and give it a name, in the example below, I'm using 'jup1'.
python3 -m venv jup1
Activate the the virtual environment.
Now that the venv is active we can install JupyterLab.
pip install jupyterlab
- The shortcuts for Jupyter Notebooks really help to speed up working with them. It pays to invest some time in learning them. Or, if you can't be bothered with that, just remember that 'shift' + 'return' runs a cell.
- If you want to check your notebooks into version control, such as github, make sure you clear the outputs first. To do so right-click on the notebook, or Edit > Clear All Outputs. Then save and do your commits.
Top comments (5)
Well, since two months (update Mac OS?) my Jupyter Labs doesn't work. It gives “ModuleNotFoundError”. A collegue tipped your blogpost, but that doesn't work for me, unfortunately. I made a virtual environment, installed Jupyter Lab and started, but got the same error.
I hope you can help me further.
Hi, I'm running macOS 10.15.7.
I've just run through the commands as posted above and it works for me. Not particularly helpful for you, I understand.
“ModuleNotFoundError” looks like a Python error, it should have an additional message that tells you which module is missing.
And, if I have followed your instructions above and have installed Jupyter Lab, how do I handle the second time when I open Terminal?
Well, all the modules are missing, it seems that python looks in the wrong directory?
Sounds like you have not activated the virtual environment, if you had, then there would be a local python interpreter and the required dependencies i.e. those modules.
When you run this a second time, you need to start at step 4 and activate the virtual environment again.