Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
duchuyvp opened this issue Dec 19, 2024 · 6 comments
Open
Labels
help wanted Extra attention is needed

Comments

@duchuyvp
Copy link

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.

@coder-labeler coder-labeler bot added the help wanted Extra attention is needed label Dec 19, 2024
@duchuyvp
Copy link
Author

duchuyvp commented Dec 19, 2024

I have a workaround solution is provide correct kernel at startup script and choose right kernel when create Notebook

resource "coder_agent" "main" {
  os             = "linux"
  arch           = "amd64"
  startup_script = <<-EOT
    set -e
    .....
    python3.12 -m pip install ipykernel --break-system-packages
    python3.12 -m ipykernel install --user --name="Python3.12.3"
    .....
  EOT

it works, but I think this is module's problem.

@matifali
Copy link
Member

The module uses pipx to manage packages to avoid the limitation introduced in Ubuntu 24.04 that doesn't let you install packages at the system level.

@duchuyvp
Copy link
Author

duchuyvp commented Dec 19, 2024

I've tried and it doesn't work
Image
Did I do something wrong? Also tried for --include-deps and --force params

@matifali
Copy link
Member

It's unfortunate that the change breaks your use case. pipx handles the installation of tools by creating an isolated environment.

@matifali
Copy link
Member

Maybe using uv would be a good option in the future.
It is easier to install, does not require any dependencies, and can managethe Python versions too.

@ktrueda
Copy link

ktrueda commented Dec 28, 2024

resource "coder_agent" "foo" {
  startup_script          = <<-EOT
    set -e
    # Add any commands that should be executed at workspace startup (e.g install requirements, start a program, etc) 
    sleep 100 # wait for jupyterlab install
    pipx inject jupyterlab pandas
  EOT
}

This is my work around. Sleep is so ugly. I hope that jupyterlab module handles tools like poetry natively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants