napari-console Plugin
napari-console is a napari plugin that integrates an interactive Python console (powered by `qtconsole`) directly into the napari viewer. It allows users to programmatically interact with the currently active napari viewer and its layers, widgets, and data. The current version is 0.1.4, with a release cadence tied to napari's development and specific feature/bug fix needs for the console functionality.
Common errors
-
ModuleNotFoundError: No module named 'napari_console'
cause The `napari-console` package (or `napari` itself) is not installed in the active Python environment.fixInstall the package using pip: `pip install napari-console` (and `pip install napari` if napari is also missing). -
Console window does not appear after selecting 'Plugins > napari-console: Console'
cause Possible compatibility issues between `napari-console`, `napari`, or `qtconsole`, or a corrupted installation.fixEnsure all related packages are up-to-date and compatible: `pip install --upgrade napari napari-console qtconsole`. Check the napari console output for specific error messages. -
NameError: name 'my_variable' is not defined (when using a variable in the console)
cause The variable `my_variable` was defined in a script or another scope outside the napari-console's current interactive session.fixRedefine or import the variable within the napari-console session, or ensure it's part of the `viewer`'s namespace if intended for interaction with napari objects.
Warnings
- gotcha napari-console requires specific versions of `napari` and `qtconsole`. Ensure your environment satisfies `napari>=0.4.17` and `qtconsole>=5.3.0` to avoid display issues or errors.
- gotcha The console is a GUI element and must be explicitly opened via the 'Plugins' menu in the napari application. It does not automatically appear on napari startup.
- gotcha The console operates within the context of the running napari viewer. While `viewer` is automatically available, other Python objects or variables defined in scripts *outside* the napari process will not be accessible unless explicitly imported or redefined within the console.
- gotcha Issues with `qtconsole` (e.g., version conflicts with other packages, missing `ipython` kernels, or display issues on specific Qt backends) can directly impact napari-console's functionality or prevent it from launching.
Install
-
pip install napari-console -
pip install napari napari-console
Imports
- napari_console
import napari_console
Quickstart
import napari # Ensure both napari and napari-console are installed: # pip install napari napari-console # 1. Start the napari viewer viewer = napari.Viewer() # 2. To open the console, in the running napari application: # Go to 'Plugins' in the top menu bar. # Select 'napari-console: Console'. # A new console widget will appear, automatically providing access to the 'viewer' object. # Example commands to type directly into the napari console: # print(viewer) # viewer.add_points([[0, 0], [10, 10], [5, 5]], text='Hello') # Keep napari running (essential for GUI interaction) napari.run()