### Setup Development Environment Source: https://github.com/jupyter/notebook/blob/main/CONTRIBUTING.md Installs Python, NodeJS, and development dependencies. Activates the environment and installs the package in development mode. Use `mamba` for faster environment creation. ```bash mamba create -n notebook -c conda-forge python nodejs -y mamba activate notebook pip install -e ".[dev,docs,test]" jlpm jlpm build jlpm develop jupyter server extension enable notebook ``` -------------------------------- ### Notebook 7 Development Setup Source: https://context7.com/jupyter/notebook/llms.txt Set up a development environment by creating a conda environment, installing dependencies in editable mode, building packages, and linking the lab extension. Start the development server using `jlpm watch` and `jupyter notebook --no-browser`. ```bash # 1. Create and activate a conda environment mamba create -n notebook -c conda-forge python nodejs -y mamba activate notebook # 2. Install in editable mode with all extras pip install -e ".[dev,docs,test]" # 3. Install JS dependencies and build all packages jlpm jlpm build # 4. Link the lab extension for development (watches for changes) jlpm develop # 5. Enable the server extension jupyter server extension enable notebook # 6. Start the development server (rebuilds on file changes) jlpm watch # in one terminal jupyter notebook --no-browser # in another terminal # Verify server extension is loaded: jupyter server extension list ``` -------------------------------- ### Setup Development Environment for Jupyter Notebook Source: https://github.com/jupyter/notebook/blob/main/docs/source/contributing.md Installs Python, NodeJS, and development dependencies, then builds and links the notebook extension and schemas. ```bash mamba create -n notebook -c conda-forge python nodejs -y mamba activate notebook pip install -e ".[dev,docs,test]" jlpm jlpm build jlpm develop jupyter server extension enable notebook ``` -------------------------------- ### Setup and Run End-to-End Tests Source: https://github.com/jupyter/notebook/blob/main/CONTRIBUTING.md Installs necessary packages for end-to-end tests, including Playwright. Starts the Jupyter server and then runs the Playwright tests. ```bash cd ui-tests jlpm jlpm playwright install jlpm start ``` ```bash jlpm test ``` -------------------------------- ### Install Prerelease Notebook with Pip Source: https://github.com/jupyter/notebook/blob/main/docs/source/development_faq.md Use the `--pre` flag with pip to install beta or release candidate versions of the notebook. ```bash python -m pip install notebook --pre --upgrade ``` -------------------------------- ### Install Real Time Collaboration Extension (pip) Source: https://github.com/jupyter/notebook/blob/main/docs/source/notebook_7_features.md Install the real-time collaboration extension using pip. Restart the Jupyter Server after installation for the extension to be loaded. ```bash pip install jupyter-collaboration ``` -------------------------------- ### Install Release Dependencies Source: https://github.com/jupyter/notebook/blob/main/RELEASE.md Installs necessary tools for manual release: hatch for versioning and building, and twine for publishing. ```bash pip install hatch twine git pull origin $(git branch --show-current) git clean -dffx ``` -------------------------------- ### Install and Enable Real-Time Collaboration Source: https://context7.com/jupyter/notebook/llms.txt Install the `jupyter-collaboration` package using pip or conda to enable simultaneous multi-user editing. Restart the server after installation. ```bash pip install jupyter-collaboration # or conda install -c conda-forge jupyter-collaboration # Then restart the server: jupyter notebook ``` -------------------------------- ### Install Jupyter Notebook Source: https://github.com/jupyter/notebook/blob/main/README.md Install Jupyter Notebook using pip. Ensure pip is installed and up-to-date. ```bash pip install notebook ``` -------------------------------- ### Install Real Time Collaboration Extension (conda) Source: https://github.com/jupyter/notebook/blob/main/docs/source/notebook_7_features.md Install the real-time collaboration extension using conda. Restart the Jupyter Server after installation for the extension to be loaded. ```bash conda install -c conda-forge jupyter-collaboration ``` -------------------------------- ### Connect to Existing Kernel Source: https://github.com/jupyter/notebook/blob/main/docs/source/notebook.md Manually start a Qt console connected to an existing kernel by providing a portion of its ID. If no ID is given, it connects to the most recently started kernel. ```bash $ jupyter qtconsole --existing 87f7d2c0 ``` -------------------------------- ### Install and Launch Jupyter Notebook Source: https://context7.com/jupyter/notebook/llms.txt Install the notebook package using pip and launch the server from the command line. Options are available to specify port, disable browser auto-open, and set the working directory. ```bash # Install pip install notebook # Launch (opens browser at http://127.0.0.1:8888) jupyter notebook # Launch on a specific port, no browser auto-open jupyter notebook --port=9999 --no-browser # Launch in a specific directory jupyter notebook --notebook-dir=/path/to/my/projects # Open a specific notebook directly jupyter notebook my_analysis.ipynb # Generate a server config file (creates ~/.jupyter/jupyter_server_config.py) jupyter server --generate-config ``` -------------------------------- ### Install a Custom Theme using pip Source: https://github.com/jupyter/notebook/blob/main/docs/source/migrating/custom-themes.md Use this command to install a custom theme package from PyPI. After installation, refresh the page to see the new theme in the settings menu. ```bash pip install jupyterlab-night ``` -------------------------------- ### Install Pre-commit and Hooks Source: https://github.com/jupyter/notebook/blob/main/CONTRIBUTING.md Install pre-commit and its git hooks to automatically format code. This ensures consistent code style across the project. ```shell pip install pre-commit pre-commit install ``` -------------------------------- ### Install Prerelease Notebook with Conda/Mamba Source: https://github.com/jupyter/notebook/blob/main/docs/source/development_faq.md Install prerelease versions of the notebook using alpha or beta labels with conda or mamba. Specify the exact version for alpha releases. ```bash conda install -c conda-forge -c conda-forge/label/notebook_alpha notebook=7.0.0a18 ``` -------------------------------- ### List Server Extensions Source: https://github.com/jupyter/notebook/blob/main/CONTRIBUTING.md Verifies if the notebook server extension is installed and enabled. Displays configuration directories and extension status. ```bash jupyter server extension list ``` -------------------------------- ### Run pywin32 post-installation script Source: https://github.com/jupyter/notebook/blob/main/docs/source/troubleshooting.md After installing or reinstalling pywin32, run this script to complete the installation and ensure proper integration with the system. Ensure 'Scripts' is the correct path for your Python installation. ```bash python.exe Scripts/pywin32_postinstall.py -install ``` -------------------------------- ### Install JupyterLab LSP Extension with Pip Source: https://github.com/jupyter/notebook/blob/main/docs/source/notebook_7_features.md Use pip to install the Language Server Protocol extension for enhanced code completion in Notebook 7. ```bash pip install jupyter-lsp ``` -------------------------------- ### Install French Language Pack (pip) Source: https://github.com/jupyter/notebook/blob/main/docs/source/notebook_7_features.md Install the French language pack for Notebook 7 using pip. After installation, reload the page and the new language should be available in the settings. ```shell pip install jupyterlab-language-pack-fr-FR ``` -------------------------------- ### Launch Qt Console Connected to Kernel Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Connecting with the Qt Console.ipynb The `%qtconsole` magic command automatically detects the current kernel's connection information and launches a new Qt Console instance connected to it. This is a convenient way to start a Qt Console for the active kernel. ```ipython a = 10 ``` ```ipython %qtconsole ``` -------------------------------- ### Start Application in Codespaces Source: https://github.com/jupyter/notebook/blob/main/CONTRIBUTING.md Start the Jupyter Notebook application within a GitHub Codespace. The URL to access it will appear in a popup or the 'Forwarded ports' panel. ```shell pixi run start ``` -------------------------------- ### Install Jupyter Widgets Source: https://github.com/jupyter/notebook/blob/main/binder/example.ipynb Install the ipywidgets package to enable Jupyter Widgets rendering in both JupyterLab and Jupyter Notebook. Reload the page after installation. ```python !pip install ipywidgets ``` -------------------------------- ### Markdown Table Example Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Working With Markdown Cells.ipynb Create tables in Markdown using pipes and hyphens for structure. This example demonstrates a simple two-column table. ```markdown | This | is | |------|------| | a | table| ``` -------------------------------- ### Kernel Started Message Source: https://github.com/jupyter/notebook/blob/main/docs/source/notebook.md This message is printed to the terminal when a kernel starts, providing its unique ID. This ID is used to connect to the kernel from other clients. ```text [JupyterNotebookApp] Kernel started: 87f7d2c0-13e3-43df-8bb8-1bd37aaf3373 ``` -------------------------------- ### Install JupyterLab LSP Extension with Conda Source: https://github.com/jupyter/notebook/blob/main/docs/source/notebook_7_features.md Use conda to install the Language Server Protocol extension for enhanced code completion in Notebook 7. ```bash conda install -c conda-forge jupyter-lsp ``` -------------------------------- ### Update Local Dependency in Notebook Source: https://github.com/jupyter/notebook/blob/main/docs/source/contributing.md Builds the local dependency package and pushes it, then installs updated dependencies in Notebook. ```bash jlpm build && yalc push yarn install ``` -------------------------------- ### Run Test Builds and Tests Source: https://github.com/jupyter/notebook/blob/main/CONTRIBUTING.md Executes the build process specifically for tests and then runs the test suite. Ensure all dependencies are installed before running. ```bash jlpm run build:test ``` ```bash jlpm run test ``` -------------------------------- ### Manage Local JavaScript Packages with Yalc Source: https://github.com/jupyter/notebook/blob/main/docs/source/contributing.md Installs yalc, publishes a local package, adds it as a dependency/resolution in Notebook, and builds with the local package. ```bash npm install -g yalc yalc publish yalc add your_package jlpm install && jlpm build ``` -------------------------------- ### Specify Notebook Port Source: https://github.com/jupyter/notebook/blob/main/docs/source/notebook.md When starting a notebook server, you can manually specify the port to use with the --port option. This is useful if you need to run multiple servers. ```bash jupyter notebook --port 8889 ``` -------------------------------- ### Get IPython Kernel Connection Info Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Connecting with the Qt Console.ipynb Use the `%connect_info` magic command to display the necessary connection details for the current IPython kernel. This information is required for manually connecting other frontends. ```ipython %connect_info ``` -------------------------------- ### Asynchronous Output Display Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Running Code.ipynb Illustrates how output is displayed asynchronously as it is generated. This example prints numbers with a short delay between each. ```python import sys import time for i in range(8): print(i) time.sleep(0.5) ``` -------------------------------- ### Install JupyterLab Extensions via pip Source: https://context7.com/jupyter/notebook/llms.txt Install various JupyterLab-compatible extensions, such as themes, language support, collaboration tools, and presentation tools, using pip. These extensions work with Notebook 7. ```bash # Install a JupyterLab-compatible extension (works in Notebook 7) pip install jupyterlab-night # dark theme pip install jupyter-lsp # Language Server Protocol (code completion) pip install jupyter-collaboration # real-time multi-user collaboration pip install rise # slideshow presentations # Install a language pack (internationalization) pip install jupyterlab-language-pack-fr-FR # French pip install jupyterlab-language-pack-zh-CN # Simplified Chinese ``` -------------------------------- ### Markdown Headings Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Working With Markdown Cells.ipynb Create headings in Markdown by starting a line with one or more '#' characters followed by a space. ```markdown # Heading 1 # Heading 2 ## Heading 2.1 ## Heading 2.2 ``` -------------------------------- ### Open Specific Notebook Source: https://github.com/jupyter/notebook/blob/main/docs/source/notebook.md Start the Jupyter Notebook server and directly open a specific notebook file, bypassing the dashboard. The .ipynb extension is assumed if not provided. ```bash jupyter notebook my_notebook.ipynb ``` -------------------------------- ### Copy Notebook into IPython Utils Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Importing Notebooks.ipynb Copies a notebook file ('mynotebook.ipynb') into the IPython utility directory. This is done to demonstrate importing notebooks from within the IPython installation itself. ```python import shutil from IPython.paths import get_ipython_package_dir utils = os.path.join(get_ipython_package_dir(), 'utils') shutil.copy( os.path.join("nbpackage", "mynotebook.ipynb"), os.path.join(utils, "inside_ipython.ipynb") ) ``` -------------------------------- ### Reinstall pywin32 using conda Source: https://github.com/jupyter/notebook/blob/main/docs/source/troubleshooting.md If using conda, this command forces a reinstallation of pywin32, which can resolve corrupted installations. ```bash conda install --force-reinstall pywin32 ``` -------------------------------- ### Upgrade pywin32 using pip Source: https://github.com/jupyter/notebook/blob/main/docs/source/troubleshooting.md Use this command to upgrade the pywin32 package if it is not installed correctly or causing issues. ```bash pip install --upgrade pywin32 ``` -------------------------------- ### Real-Time Collaboration Usage Source: https://context7.com/jupyter/notebook/llms.txt Once `jupyter-collaboration` is installed, users can open the same `.ipynb` URL to collaborate in real-time. Notebook 7 and JupyterLab share the same RTC document model, displaying cursors and edits instantly. ```python # After installing, multiple users can open the same .ipynb URL. # Notebook 7 and JupyterLab share the same RTC document model. # Users connecting to http://127.0.0.1:8888/notebooks/shared.ipynb # will see each other's cursors and edits in real time. # No additional Python API is needed; the extension is auto-loaded # via the jupyter_server extension mechanism. ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/jupyter/notebook/blob/main/CONTRIBUTING.md Serve the built documentation locally for preview. Access it via http://localhost:8000 in your web browser. ```shell hatch run docs:serve ``` -------------------------------- ### Build Documentation Source: https://github.com/jupyter/notebook/blob/main/CONTRIBUTING.md Build the project documentation using the hatch build command. This generates static files for the documentation. ```shell hatch run docs:build ``` -------------------------------- ### pywin32 ImportError: DLL load failed (invalid application) Source: https://github.com/jupyter/notebook/blob/main/docs/source/troubleshooting.md This error suggests an issue with the pywin32 installation, possibly due to a mismatch between the installed package and the Windows environment (32-bit vs. 64-bit). Verify your installation and environment compatibility. ```default File "C:\Users\jovyan\AppData\Roaming\Python\Python37\site-packages\jupyter_core\paths.py", line 435, in secure_write win32_restrict_file_to_user(fname) File "C:\Users\jovyan\AppData\Roaming\Python\Python37\site-packages\jupyter_core\paths.py", line 361, in win32_restrict_file_to_user import win32api ImportError: DLL load failed: %1 is not a valid Win32 application ``` -------------------------------- ### Import a notebook package Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Importing Notebooks.ipynb Demonstrates importing a notebook named 'mynotebook' from a package named 'nbpackage' after the finder has been registered. ```python import nbpackage.mynotebook ``` -------------------------------- ### Initialize and Configure NotebookApp in TypeScript Source: https://context7.com/jupyter/notebook/llms.txt Instantiate the main application class and register plugin modules. The application version and paths are accessible after initialization. ```typescript // packages/application/src/app.ts import { NotebookApp } from '@jupyter-notebook/application'; import { NotebookShell } from '@jupyter-notebook/application'; // Create with a custom shell const app = new NotebookApp({ shell: new NotebookShell() }); // Register a single plugin module app.registerPluginModule(myPluginModule); // where myPluginModule.default is a JupyterFrontEndPlugin or an array of them // Register multiple plugin modules at once app.registerPluginModules([moduleA, moduleB, moduleC]); // Read version from page config console.log(app.version); // e.g. "7.5.0" // Access application paths (all sourced from PageConfig) console.log(app.paths.urls.base); // "/" console.log(app.paths.urls.settings); // "/api/settings" console.log(app.paths.directories.schemas); // path to schemas dir // Format automatically toggles between 'mobile' and 'desktop' // based on a CSS media query (max-width: 760px) console.log(app.format); // "desktop" or "mobile" // Wait for shell restoration await app.restored; ``` -------------------------------- ### Install JupyterLab Extensions via Conda Source: https://context7.com/jupyter/notebook/llms.txt Install JupyterLab extensions, like jupyter-collaboration, using the conda package manager from the conda-forge channel. ```bash # Install via conda conda install -c conda-forge jupyter-collaboration ``` -------------------------------- ### Binomial Probability Formula using equation* environment Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Typesetting Equations.ipynb The \begin{equation*} environment is suitable for displaying formulas like the binomial probability, which involves combinations and powers. ```tex \begin{equation*} P(E) = {n \choose k} p^k (1-p)^{ n-k} \end{equation*} ``` -------------------------------- ### Run All Files with Pre-commit Source: https://github.com/jupyter/notebook/blob/main/docs/source/contributing.md Fix formatting issues in all files using pre-commit hooks. A subsequent commit is required. ```shell pre-commit run --all-files ``` -------------------------------- ### Initializing HTMLFormatter and PythonLexer Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Importing Notebooks.ipynb Sets up the HTMLFormatter and PythonLexer, which are typically used for syntax highlighting and formatting code output in HTML. ```python formatter = HtmlFormatter() lexer = PythonLexer() ``` -------------------------------- ### Cross Product Formula using equation* environment Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Typesetting Equations.ipynb Use the \begin{equation*} environment for unnumbered display equations, particularly for matrices or determinants. ```tex \begin{equation*} \mathbf{V}_1 \times \mathbf{V}_2 = \begin{vmatrix} \mathbf{i} & \mathbf{j} & \mathbf{k} \\ \frac{\partial X}{\partial u} & \frac{\partial Y}{\partial u} & 0 \\ \frac{\partial X}{\partial v} & \frac{\partial Y}{\partial v} & 0 \end{vmatrix} \end{equation*} ``` -------------------------------- ### Build All Packages Source: https://github.com/jupyter/notebook/blob/main/CONTRIBUTING.md Builds all packages within the monorepo structure. This command should be run from the Notebook root directory. ```bash jlpm build ``` -------------------------------- ### Execute Python Code Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Running Code.ipynb This snippet shows how to execute a simple Python command. Ensure the necessary libraries are imported if required. ```python # libc.time(-1) # BOOM!! 15914343565113172548972231940698266883214596825515126958094847260581103904401068017057791 31828687130226345097944463881396533766429193651030253916189694521162207808802136034115583 63657374260452690195888927762793067532858387302060507832379389042324415617604272068231167 127314748520905380391777855525586135065716774604121015664758778084648831235208544136462335 254629497041810760783555711051172270131433549208242031329517556169297662470417088272924671 509258994083621521567111422102344540262867098416484062659035112338595324940834176545849343 1018517988167243043134222844204689080525734196832968125318070224677190649881668353091698687 ``` -------------------------------- ### Automatic Scrolling Output Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Running Code.ipynb Demonstrates output that automatically scrolls when it exceeds the visible area. This example prints a large sequence of numbers. ```python for i in range(500): print(2**i - 1) ``` -------------------------------- ### Lorenz Equations using align environment Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Typesetting Equations.ipynb Use the \begin{align} environment for multi-line equations with alignment points. This is suitable for complex systems of equations. ```tex \begin{align} \dot{x} & = \sigma(y-x) \\ \dot{y} & = \rho x - y - xz \\ \dot{z} & = -\beta z + xy \end{align} ``` -------------------------------- ### Import Notebook from IPython Utils Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Importing Notebooks.ipynb Imports a notebook that has been copied into the IPython utility directory. This demonstrates the ability to import notebooks from system-level directories. ```python from IPython.utils import inside_ipython inside_ipython.whatsmyname() ``` -------------------------------- ### Maxwell's Equations using align environment Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Typesetting Equations.ipynb Use the \begin{align} environment to typeset systems of equations like Maxwell's equations, ensuring proper alignment and readability. ```tex \begin{align} \nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\ \nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\ \nabla \cdot \vec{\mathbf{B}} & = 0 \end{align} ``` -------------------------------- ### Activate Development Environment in Codespaces Source: https://github.com/jupyter/notebook/blob/main/CONTRIBUTING.md Activate the development environment within a GitHub Codespace using the pixi shell command. ```shell pixi shell ``` -------------------------------- ### Managing Jupyter Extensions Source: https://context7.com/jupyter/notebook/llms.txt Notebook 7 utilizes the JupyterLab extension system. Extensions are Python packages with prebuilt JavaScript assets that can be installed using pip or conda. ```APIDOC ## Installing and Managing Extensions Notebook 7 uses the JupyterLab extension system. Extensions are Python packages containing prebuilt JavaScript assets, installed via `pip` or `conda`. ```bash # Install a JupyterLab-compatible extension (works in Notebook 7) pip install jupyterlab-night # dark theme pip install jupyter-lsp # Language Server Protocol (code completion) pip install jupyter-collaboration # real-time multi-user collaboration pip install rise # slideshow presentations # Install a language pack (internationalization) pip install jupyterlab-language-pack-fr-FR # French pip install jupyterlab-language-pack-zh-CN # Simplified Chinese # List installed extensions jupyter labextension list # Disable a specific plugin within an extension jupyter labextension disable @jupyterlab/filebrowser-extension:download # Re-enable it jupyter labextension enable @jupyterlab/filebrowser-extension:download # Install via conda conda install -c conda-forge jupyter-collaboration ``` ``` -------------------------------- ### Manage Jupyter Extensions Source: https://context7.com/jupyter/notebook/llms.txt Manage installed JupyterLab extensions by listing them, disabling specific plugins within an extension, or re-enabling them. This is done using the `jupyter labextension` command. ```bash # List installed extensions jupyter labextension list # Disable a specific plugin within an extension jupyter labextension disable @jupyterlab/filebrowser-extension:download # Re-enable it jupyter labextension enable @jupyterlab/filebrowser-extension:download ``` -------------------------------- ### Run Jupyter Notebook Locally Source: https://github.com/jupyter/notebook/blob/main/README.md Launch the Jupyter Notebook server in your local environment. ```bash jupyter notebook ``` -------------------------------- ### pywin32 ImportError: DLL load failed (module not found) Source: https://github.com/jupyter/notebook/blob/main/docs/source/troubleshooting.md This traceback indicates that the pywin32 module, required for interacting with Windows primitives, could not be found. Ensure pywin32 is installed correctly. ```default File "c:\users\jovyan\python\myenv.venv\lib\site-packages\jupyter_core\paths.py", line 424, in secure_write win32_restrict_file_to_user(fname) File "c:\users\jovyan\python\myenv.venv\lib\site-packages\jupyter_core\paths.py", line 359, in win32_restrict_file_to_user import win32api ImportError: DLL load failed: The specified module could not be found. ``` -------------------------------- ### List Available Kernels Source: https://github.com/jupyter/notebook/blob/main/docs/source/troubleshooting.md Use this command to see where Jupyter stores kernel specifications and identify available kernels on your system. This is useful for diagnosing kernel startup issues. ```bash $ jupyter kernelspec list Available kernels: python3 /home/takluyver/.local/lib/python3.6/site-packages/ipykernel/resources bash /home/takluyver/.local/share/jupyter/kernels/bash ir /home/takluyver/.local/share/jupyter/kernels/ir ``` -------------------------------- ### Get Current Module Name in Python Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/nbpackage/mynotebook.ipynb A Python function that returns the name of the current module using the `__name__` special variable. This is useful for checking if a script is run directly or imported. ```python def whatsmyname(): return __name__ ``` -------------------------------- ### Discover Jupyter Server Extensions Source: https://context7.com/jupyter/notebook/llms.txt Use discovery hooks from the `notebook` package to allow `jupyter server` to auto-load the notebook extension. This includes discovering server extension paths, extension points, and prebuilt labextension assets. ```python import notebook # Discover the server extension paths = notebook._jupyter_server_extension_paths() # [{"module": "notebook"}] # Discover the extension app (used by jupyter_server >=2.x) points = notebook._jupyter_server_extension_points() # [{"module": "notebook", "app": }] # Discover the prebuilt labextension assets lab_paths = notebook._jupyter_labextension_paths() # [{"src": "labextension", "dest": "@jupyter-notebook/lab-extension"}] # Enable manually via CLI: # $ jupyter server extension enable notebook # Verify installation: # $ jupyter server extension list ``` -------------------------------- ### Get Jupyter Notebook Version Information Source: https://context7.com/jupyter/notebook/llms.txt Access the current version string and structured version information using the `_version` module. The `version_info` named tuple provides major, minor, micro, release level, and serial components. ```python from notebook._version import __version__, version_info print(__version__) # "7.6.0a5" print(version_info) # VersionInfo(major=7, minor=6, micro=0, releaselevel='a', serial='5') print(version_info.major, version_info.minor) # 7 6 ``` -------------------------------- ### Build Distribution Artifacts Source: https://github.com/jupyter/notebook/blob/main/RELEASE.md Removes any existing distribution files and then builds new distribution artifacts (e.g., wheels, sdists) using hatch. ```bash rm -rf dist hatch build ``` -------------------------------- ### ImportError: Module 'random' has no attribute 'sample' due to naming conflict Source: https://github.com/jupyter/notebook/blob/main/docs/source/troubleshooting.md This traceback indicates a naming conflict where a user-created file named 'random.py' is interfering with the import of the built-in 'random' module. Rename your file to avoid conflicts with installed packages. ```default File "C:\Users\jovyan\anaconda3\lib\site-packages\ipykernel\connect.py", line 13, in from IPython.core.profiledir import ProfileDir File "C:\Users\jovyan\anaconda3\lib\site-packages\IPython__init__.py", line 55, in from .core.application import Application ... File "C:\Users\jovyan\anaconda3\lib\site-packages\ipython_genutils\path.py", line 13, in import random File "C:\Users\jovyan\Desktop\Notebooks\random.py", line 4, in rand_set = random.sample(english_words_lower_set, 12) AttributeError: module 'random' has no attribute 'sample' ``` -------------------------------- ### List Notebooks in Package Directory Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Importing Notebooks.ipynb Lists the contents of the 'nbpackage/nbs' directory using the 'ls' command. This is useful for verifying the presence of notebook files within a package structure. ```shell ls nbpackage/nbs ``` -------------------------------- ### Importing notebookapp from notebook (Old) Source: https://github.com/jupyter/notebook/blob/main/docs/source/migrating/server-imports.md This is the old way of importing the notebookapp module from the notebook package. ```python from notebook import notebookapp notebookapp.list_running_servers() ``` -------------------------------- ### Programmatic Notebook Launch Source: https://context7.com/jupyter/notebook/llms.txt Launch the Jupyter Notebook server programmatically using the `JupyterNotebookApp` class. Key configurable traitlets are listed for customization. ```python # notebook/app.py from notebook.app import JupyterNotebookApp # Programmatic launch (equivalent to `jupyter notebook`) JupyterNotebookApp.launch_instance() # Or via the installed console script: # $ jupyter-notebook --port=8888 --no-browser # Key configurable traitlets: # JupyterNotebookApp.default_url (default: "/tree") # JupyterNotebookApp.expose_app_in_browser (default: False) # JupyterNotebookApp.custom_css (default: True) # Disable custom CSS loading: # $ jupyter notebook --JupyterNotebookApp.custom_css=False # Expose the app as window.jupyterapp in the browser (for debugging): # $ jupyter notebook --expose-app-in-browser ``` -------------------------------- ### Generate Jupyter Server Configuration Source: https://github.com/jupyter/notebook/blob/main/docs/source/configuring/config_overview.md Use this command to create a jupyter_server_config.py file in the .jupyter directory with all default settings commented out. ```bash $ jupyter server --generate-config ``` -------------------------------- ### Importing passwd from notebook.auth (Old) Source: https://github.com/jupyter/notebook/blob/main/docs/source/migrating/server-imports.md This is the old way of importing the passwd function from the notebook package. ```python from notebook.auth import passwd passwd("foo") ``` -------------------------------- ### Run Pre-commit Hooks Manually Source: https://github.com/jupyter/notebook/blob/main/CONTRIBUTING.md Manually invoke pre-commit hooks to format all staged files or all files in the repository. Use `--all-files` to format the entire codebase. ```shell pre-commit run ``` ```shell pre-commit run --all-files ``` -------------------------------- ### Cauchy-Schwarz Inequality using equation* environment Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Typesetting Equations.ipynb Employ the \begin{equation*} environment for unnumbered display equations. This is useful for standalone mathematical statements. ```tex \begin{equation*} \left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right) \end{equation*} ``` -------------------------------- ### List directory contents Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Importing Notebooks.ipynb A shell command to list the contents of the 'nbpackage' directory, useful for verifying the structure before importing. ```shell ls nbpackage ``` -------------------------------- ### Publish Artifacts to PyPI Source: https://github.com/jupyter/notebook/blob/main/RELEASE.md Checks the distribution artifacts for common issues and then uploads them to the Python Package Index (PyPI) using twine. ```bash twine check dist/* twine upload dist/* ``` -------------------------------- ### Ramanujan's Identity using equation* environment Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Typesetting Equations.ipynb Render complex mathematical identities, such as Ramanujan's continued fraction, using the \begin{equation*} environment for display. ```tex \begin{equation*} \frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {\frac{e^{-8\pi}} {1+\ldots} } } } \end{equation*} ``` -------------------------------- ### Watch for Changes and Rebuild Source: https://github.com/jupyter/notebook/blob/main/CONTRIBUTING.md Automatically rebuilds the application when changes are detected. Useful during active development. ```bash jlpm watch ``` -------------------------------- ### Update Version and Tag Release Source: https://github.com/jupyter/notebook/blob/main/RELEASE.md Prompts for a new version, updates the project version using hatch, and creates an annotated Git tag for the release. ```bash echo "Enter new version" read new_version hatch version ${new_version} git tag -a ${new_version} -m "Release ${new_version}" ``` -------------------------------- ### Migrated Server Imports Source: https://context7.com/jupyter/notebook/llms.txt In Notebook 7, server utility functions previously located in the `notebook` package have been moved to `jupyter_server`. Update your code to reflect these import changes. ```APIDOC ## Migrated Server Imports (Notebook 7) In Notebook 7, server utility functions previously in the `notebook` package have moved to `jupyter_server`. Update any code that imports from the old locations. ```python # ── BEFORE (Classic Notebook / Notebook < 7) ────────────────────────────── from notebook.auth import passwd hashed = passwd("mypassword") from notebook import notebookapp servers = notebookapp.list_running_servers() # ── AFTER (Notebook 7 / jupyter_server) ─────────────────────────────────── from jupyter_server.auth import passwd hashed = passwd("mypassword") # Returns: 'argon2:...' or 'sha1:...' hash string from jupyter_server import serverapp servers = list(serverapp.list_running_servers()) # Returns: list of dicts with keys: pid, port, base_url, notebook_dir, token, ... for s in servers: print(f"Server at http://127.0.0.1:{s['port']} root={s['notebook_dir']}") ``` ``` -------------------------------- ### Syntax highlighting imports Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Importing Notebooks.ipynb Imports necessary components from Pygments for syntax highlighting, typically used for displaying code with formatting. ```python from pygments import highlight from pygments.lexers import PythonLexer from pygments.formatters import HtmlFormatter ``` -------------------------------- ### Display Another Notebook Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Importing Notebooks.ipynb Displays the content summary of another notebook file located at 'nbpackage/nbs/other.ipynb'. This function is used to inspect the cells of different notebooks. ```python show_notebook(os.path.join("nbpackage", "nbs", "other.ipynb")) ``` -------------------------------- ### Configure Jupyter Server Options Source: https://context7.com/jupyter/notebook/llms.txt Set persistent server options by generating and editing the `jupyter_server_config.py` file. This includes port, browser opening behavior, notebook directory, remote access, and origin. ```python # Generate config template: # $ jupyter server --generate-config # Creates: ~/.jupyter/jupyter_server_config.py # Example ~/.jupyter/jupyter_server_config.py c.ServerApp.port = 8888 c.ServerApp.open_browser = False c.ServerApp.notebook_dir = '/home/user/notebooks' c.ServerApp.allow_remote_access = True c.ServerApp.allow_origin = '*' # only for trusted networks # Password protection (Notebook 7 uses jupyter_server) from jupyter_server.auth import passwd c.ServerApp.password = passwd('mysecretpassword') # or set via CLI: jupyter notebook password # Disable token authentication (not recommended for remote servers) c.ServerApp.token = '' # Apply Notebook-specific options c.JupyterNotebookApp.default_url = '/tree' c.JupyterNotebookApp.custom_css = True c.JupyterNotebookApp.expose_app_in_browser = False # Disable custom CSS via CLI flag: # $ jupyter notebook --JupyterNotebookApp.custom_css=False ``` -------------------------------- ### Register Notebook Finder Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Importing Notebooks.ipynb Appends the custom NotebookFinder to sys.meta_path to enable importing Jupyter Notebooks. ```python sys.meta_path.append(NotebookFinder()) ``` -------------------------------- ### Print to Standard Output Source: https://github.com/jupyter/notebook/blob/main/docs/source/examples/Notebook/Running Code.ipynb Demonstrates printing a message to the standard output stream. This is the default behavior for print statements. ```python print("hi, stdout") ``` -------------------------------- ### Display an Integer Slider Widget Source: https://github.com/jupyter/notebook/blob/main/binder/example.ipynb Render the previously created IntSlider widget. This will display the interactive slider in the notebook output. ```python slider ``` -------------------------------- ### Open Markdown Preview on Left Source: https://github.com/jupyter/notebook/blob/main/docs/source/configuring/interface_customization.md Configure the Markdown Preview to open in the 'left' area by modifying the Notebook Shell settings. This is useful for viewing rendered Markdown while editing. ```json { "layout": { "Markdown Preview": { "area": "left" } } } ``` -------------------------------- ### Manage Local JavaScript Dependencies with Yalc Source: https://github.com/jupyter/notebook/blob/main/CONTRIBUTING.md Instructions for using yalc to test local JavaScript package changes. This involves publishing the local package, adding it as a dependency in Notebook, and rebuilding. ```bash npm install -g yalc ``` ```bash yalc publish ``` ```bash yalc add your_package ``` ```bash jlpm install && jlpm build ``` ```bash jlpm build && yalc push ``` ```bash yarn install ```