Skip to content

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

@yangdanny97

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

Metadata

Metadata

Assignees

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions