Skip to content

Jupyter Lab: non-activated venv obscures site-packages path for system Python #1043

Closed as not planned

Description

@yangdanny97

Describe the Bug

Directory structure:

  • scratch/venv (make an empty venv, do not activate it)
  • scratch/project/Test.ipynb

Repro:

  • pip install jupyterlab jupyter-lsp jupyterlab-lsp matplotlib
  • in scratch/project run jupyter lab
  • open/create Test.ipynb and add import matplotlib.pyplot as plt
  • observe import error

pyrefly dump-config gives the following:

 INFO Checking project configured at `/Users/dannyyang/Documents/Documents/GitHub/scratch/pyrefly.toml`
Configuration at `/Users/dannyyang/Documents/Documents/GitHub/scratch/pyrefly.toml`
  Using interpreter: /Users/dannyyang/Documents/Documents/GitHub/scratch/venv/bin/python3
  Covered files:
    /Users/dannyyang/Documents/Documents/GitHub/scratch/.pytype/imports/default.pyi
    /Users/dannyyang/Documents/Documents/GitHub/scratch/.pytype/pyi/pytype.pyi
    /Users/dannyyang/Documents/Documents/GitHub/scratch/compare.py
    /Users/dannyyang/Documents/Documents/GitHub/scratch/docs2types/extract_and_apply_annotations.py
    /Users/dannyyang/Documents/Documents/GitHub/scratch/docs2types/extract_and_apply_defaults.py
    /Users/dannyyang/Documents/Documents/GitHub/scratch/docs2types/test_package/__init__.py
    /Users/dannyyang/Documents/Documents/GitHub/scratch/docs2types/tests/__init__.py
    /Users/dannyyang/Documents/Documents/GitHub/scratch/docs2types/tests/extract_and_apply_defaults_test.py
    /Users/dannyyang/Documents/Documents/GitHub/scratch/generate_expected_output.py
    /Users/dannyyang/Documents/Documents/GitHub/scratch/mypy/compare_mypy_pyrefly.py
    ...and 8875 more
  Import root (inferred from project layout): "/Users/dannyyang/Documents/Documents/GitHub/scratch"
  Site package path queried from interpreter: ["/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12", "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/lib-dynload", "/Users/dannyyang/Documents/Documents/GitHub/scratch/venv/lib/python3.12/site-packages"]

So it's using the interpreter in the venv in the parent directory, and the site package path does not include the system python one (/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages)

Is this expected behavior?

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Activity

  1. grievejia commented on Sep 8, 2025

    @grievejia
    Contributor

    The dump-config output has /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12 as the first item in the site package path list, but the description claims that the site package path does not include /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12. Any chance you could clarify that part?

  2. yangdanny97 commented on Sep 9, 2025

    @yangdanny97
    CollaboratorAuthor

    /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12 (included)
    /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (missing)

  3. added theissue type on Sep 12, 2025
  4. MarcoGorelli commented on Feb 25, 2026

    @MarcoGorelli
    Collaborator

    open/create Test.ipynb and add import matplotlib.pyplot as plt
    observe import error

    Where does the import error happen?

    I've followed the steps but this works fine for me

    Image
  5. Carreau commented on Mar 5, 2026

    @Carreau

    This works fine for me as well; Any chance you actually created the notebook from a ipykernel installation that is in the venv ? It may be that the notebook metadata remembers that you used that kernel and somehow managed to pick it up again; so even if not activated before running jupyter-lab, you might pick up a kernel in a different place (typically if you did some python -m ipykernel install

  6. self-assigned this
    on Mar 6, 2026
  7. yangdanny97 commented on Mar 6, 2026

    @yangdanny97
    CollaboratorAuthor

    I'll try to repro this again tomorrow, if it was just a problem on my machine we can close it

  8. yangdanny97 commented on Mar 13, 2026

    @yangdanny97
    CollaboratorAuthor

    Closing due to no repro

  9. Carreau commented on Mar 16, 2026

    @Carreau

    Thanks for re-trying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions