Skip to content

Make psutil optional for constrained platforms #1523

@yves-surrel

Description

@yves-surrel

Feature request

Would it be possible to make psutil an optional dependency, or to provide a configuration flag allowing ipykernel to run without psutil on constrained platforms?

Context

I am running ipykernel inside a Python-for-Android / Kivy application. This setup works with ipykernel==6.9.1, but newer versions import psutil during kernel startup. On Android / python-for-android, psutil is difficult to support because it contains platform-specific native code and relies on process-inspection APIs that are not always available or useful in this environment.

The kernel itself works for the main use case:

  • Jupyter messaging
  • remote QtConsole control
  • normal Python execution
  • NumPy operations
  • application-side control through the kernel namespace

The blocking point is that newer ipykernel versions require psutil even though the features using it appear to be related mainly to process/resource reporting and child-process management.

Observed psutil usage

From inspection, psutil appears to be used in areas such as:

  • usage_request
  • _process_children
  • _signal_children

These seem useful on desktop/server platforms, but they are not essential for all embedded/mobile use cases.

Proposed behavior

One possible approach would be:

  • keep full psutil behavior when psutil is installed;
  • if psutil is unavailable, allow the kernel to start anyway;
  • degrade gracefully for features requiring process introspection;
  • return limited or unavailable resource information from usage_request;
  • treat child-process enumeration as empty or unsupported.

For example, ipykernel could catch ImportError around psutil and use a small internal fallback layer.

Why this would help

This would make recent ipykernel versions usable on constrained or unusual Python targets, including:

  • Android / python-for-Android
  • embedded Linux systems
  • restricted containers
  • environments where native extension builds are not practical

Currently, users in those environments may need to pin to older ipykernel versions only to avoid the hard psutil dependency.

Current workaround

For now, I can run successfully with:

ipykernel==6.9.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions