Skip to content

Unable to Import Packages that Installed with pip in JupyterLab module #35

Open
@duchuyvp

Description

@duchuyvp

I use the jupyter-lab module in main.tf with default parameters. However, when I create a new Notebook, I encounter issues with importing packages installed using pip.

Steps to reproduce:

  1. In a Notebook, run !pip install pandas --break-system-packages (using --break-system-packages to bypass the externally-managed-environment error). The package gets installed to ~/.local/lib/python3.12/site-packages.
  2. Run import pandas as pd in the Notebook. This raises a ModuleNotFoundError.

Findings:

Output of !which pip in the Notebook: /usr/bin/pip
Output of sys.executable in the Notebook: /home/coder/.local/share/pipx/venvs/jupyterlab/bin/python
It seems that when JupyterLab is installed via pipx, it uses its own Python environment, separate from the system's pip. As a result, packages installed via pip are not accessible to JupyterLab.

Expected behavior:

Packages installed using !pip install in a Jupyter notebook should be available for import without additional configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions