JupyterLab
JupyterLab is an open-source, web-based interactive development environment for notebooks, code, and data, serving as the next-generation user interface for Project Jupyter. It consolidates familiar tools like notebooks, terminals, text editors, and file browsers into a flexible and extensible interface. Currently at version 4.5.6, it is actively maintained with frequent minor and patch releases, and significant major version updates less often.
Common errors
-
ModuleNotFoundError: No module named '...' (in JupyterLab)
cause The Python package you are trying to import is either not installed in the active JupyterLab environment or there is a mismatch between the Python environment where the package was installed and the kernel being used by JupyterLab.fixFirst, ensure the package is installed in the correct environment using `pip install <package_name>` or `conda install <package_name>`. If the issue persists, check that JupyterLab is using the intended Python environment by verifying `which python` in the terminal and then in a notebook cell (`!which python`), and if different, either activate the correct environment before launching JupyterLab or install `ipykernel` in that environment and register it as a Jupyter kernel. -
A connection to the notebook server could not be established. The notebook will continue trying to reconnect. Check your network connection or notebook server configuration. (Kernel connection failed)
cause JupyterLab is unable to establish or maintain a connection with the Python kernel, which can be due to network issues, port conflicts, outdated `pyzmq` or `tornado` packages, or problems with the kernel's startup configuration.fixTry restarting the JupyterLab server. If that doesn't work, ensure your `pyzmq` and `tornado` packages are up-to-date or try downgrading them (e.g., `pip uninstall pyzmq; pip install pyzmq==19.0.2` or `conda install pyzmq==19.0.2` and similar for `tornado` to a stable version like 5.1.1 if 6.x causes issues). Also, check your terminal for specific error messages when the kernel attempts to start, and consider clearing browser cache or trying an incognito window. -
'jupyter lab' is not recognized as an internal or external command, operable program or batch file. / zsh: command not found: jupyterlab
cause The `jupyter lab` command is not found in your system's PATH environment variable, or JupyterLab was not installed in a location that is included in PATH, or the installation was incomplete/corrupted.fixFirst, try launching with `python -m jupyterlab`. If this works, it indicates a PATH issue. You may need to add the Python scripts directory (e.g., `C:\Users\user\AppData\Roaming\Python\Python39\Scripts` on Windows or `~/Library/Python/3.x/bin` on macOS) to your system's PATH. Alternatively, ensure JupyterLab is correctly installed in your active environment with `pip install jupyterlab --upgrade` or `conda install jupyterlab`. -
AttributeError: module 'random' has no attribute 'sample' (or similar AttributeError within a notebook)
cause This specific AttributeError (e.g., with 'random') often occurs when a user-created Python file in the same directory as the notebook has the same name as a standard library module, leading to a naming conflict where Python imports the local file instead of the intended module.fixRename your Python file (e.g., `random.py`) to something unique that does not conflict with existing Python modules or packages. Restart the kernel after renaming the file. -
Error searching for extensions: Error: Unhandled error (in Extension Manager)
cause JupyterLab's Extension Manager fails to search or install extensions, often due to network connectivity issues, firewall restrictions, or an outdated Node.js installation (which JupyterLab extensions rely on for building and managing front-end assets).fixEnsure you have a stable internet connection and check for any corporate firewalls or VPNs that might be blocking access to npm (Node Package Manager). Ensure Node.js is installed and up-to-date (check with `node -v` and `npm -v`). If issues persist, try installing extensions directly via the command line using `jupyter labextension install <extension-name>` and then rebuilding JupyterLab with `jupyter lab build`.
Warnings
- breaking JupyterLab 3.x extensions are generally incompatible with JupyterLab 4.x due to significant type and API changes. JupyterLab 3 reached end of maintenance on May 15, 2024, with critical fixes until December 31, 2024. Upgrade extensions and ensure compatibility when migrating to JupyterLab 4.
- gotcha If 'jupyter' command is not found after `pip install --user jupyterlab`, it's likely due to the user-level bin directory not being in your PATH environment variable.
- gotcha Avoid running `jupyter lab` from your root volume (e.g., `C:\` on Windows or `/` on Linux) to minimize the risk of inadvertently modifying system files.
- deprecated For Jupyter Notebook versions older than 5.3, enabling the JupyterLab server extension required running `jupyter serverextension enable --py jupyterlab --sys-prefix`. This step is no longer necessary for modern JupyterLab installations.
- deprecated Older 'source extensions' for JupyterLab, which required Node.js and a full JupyterLab rebuild upon installation, are deprecated. Modern prebuilt extensions are distributed as Python packages and can be installed with `pip` or `conda` without a rebuild.
- gotcha Real-time collaboration (RTC) in JupyterLab 4 has been moved into a separate package, `jupyter_collaboration`. It's no longer built-in.
- gotcha The command `jupyter lab` is a shell command, not Python syntax. Attempting to execute it directly within a Python script will result in a `SyntaxError`.
- gotcha Executing `jupyter lab` directly within a Python script will lead to a `SyntaxError` because `jupyter lab` is a shell command, not valid Python syntax.
Install
-
pip install jupyterlab
Imports
- JupyterServerApp
from jupyter_server.serverapp import JupyterServerApp
Quickstart
jupyter lab