pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

UV generated project has no completions

Open BlackDark opened this issue 6 months ago • 11 comments

Type: Bug

When I create my project with uv (tested also with newest version 0.7.6) the auto completion for imports does not work. VSCode itself recognizes the modules if manually imported but not with auto import help.

Commands to recreate:

uv init demo-bug --package
cat > demo_bug/src/demo_bug/hello.py << EOF
def sample():
  pass
EOF
uv sync

Hint: Be sure that the .venv is the active environment in vscode!

Now from __init__.py the autoimport if I type sam and press ctrl + space should be visible. But is not:

Image

Structure files:

Image

How imports work (but this is not the way to go because statically copied):

If you run uv sync --no-editable and afterwards in vscode clear cache and reload window. The import appears:

Image

Structure with --no-editable:

Image

Both variants know the modules if manually added

In both cases manually imported modules are correctly identified the only problem is the auto import from vscode:

Image

Extension version: 2025.5.1 VS Code version: Code 1.100.2 (848b80aeb52026648a8ff9f7c45a9b0a80641e2e, 2025-05-14T21:47:40.416Z) OS version: Darwin arm64 24.5.0 Modes:

System Added Logs
2025-05-20 09:26:39.337 [info] (Client) Running with node: /Users/marbaced/.vscode/extensions/ms-python.vscode-pylance-2025.5.1/dist/.cache/node/node
2025-05-20 09:26:41.021 [info] (Client) Pylance async client (2025.5.1) started with python extension (2025.6.1)
2025-05-20 09:26:41.823 [info] [Info  - 09:26:41] (15035) Server root directory: file:///Users/marbaced/.vscode/extensions/ms-python.vscode-pylance-2025.5.1/dist
2025-05-20 09:26:41.827 [info] [Info  - 09:26:41] (15035) Pylance language server 2025.5.1 (pyright version 1.1.400, commit b962ffc2) starting
2025-05-20 09:26:41.829 [info] [Info  - 09:26:41] (15035) Starting service instance "demo-bug" for workspace "/Users/marbaced/tmp/uv-test/demo-bug"
2025-05-20 09:26:41.995 [info] [Info  - 09:26:41] (15035) Loading pyproject.toml file at /Users/marbaced/tmp/uv-test/demo-bug/pyproject.toml
2025-05-20 09:26:41.995 [info] [Info  - 09:26:41] (15035) Pyproject file "/Users/marbaced/tmp/uv-test/demo-bug/pyproject.toml" has no "[tool.pyright]" section.
2025-05-20 09:26:41.995 [info] [Info  - 09:26:41] (15035) Setting environmentName for service "demo-bug": "3.13.3 (.venv venv)"
2025-05-20 09:26:41.995 [info] [Info  - 09:26:41] (15035) Setting pythonPath for service "demo-bug": "/Users/marbaced/tmp/uv-test/test2/.venv/bin/python"
2025-05-20 09:26:41.995 [info] [Info  - 09:26:41] (15035) No include entries specified; assuming /Users/marbaced/tmp/uv-test/demo-bug
2025-05-20 09:26:41.995 [info] [Info  - 09:26:41] (15035) Auto-excluding **/node_modules
2025-05-20 09:26:41.996 [info] [Info  - 09:26:41] (15035) Auto-excluding **/__pycache__
2025-05-20 09:26:41.996 [info] [Info  - 09:26:41] (15035) Auto-excluding **/.*
2025-05-20 09:26:41.996 [info] [Info  - 09:26:41] (15035) Assuming Python version 3.13.3.final.0
2025-05-20 09:26:41.996 [info] [Info  - 09:26:41] (15035) Found 1 source file
2025-05-20 09:26:42.066 [info] [Info  - 09:26:42] (15035) Loading pyproject.toml file at /Users/marbaced/tmp/uv-test/demo-bug/pyproject.toml
2025-05-20 09:26:42.066 [info] [Info  - 09:26:42] (15035) Pyproject file "/Users/marbaced/tmp/uv-test/demo-bug/pyproject.toml" has no "[tool.pyright]" section.
2025-05-20 09:26:42.066 [info] [Info  - 09:26:42] (15035) Setting environmentName for service "demo-bug": "3.13.3 (.venv venv)"
2025-05-20 09:26:42.066 [info] [Info  - 09:26:42] (15035) Setting pythonPath for service "demo-bug": "/Users/marbaced/tmp/uv-test/test2/.venv/bin/python"
2025-05-20 09:26:42.066 [info] [Info  - 09:26:42] (15035) No include entries specified; assuming /Users/marbaced/tmp/uv-test/demo-bug
2025-05-20 09:26:42.066 [info] [Info  - 09:26:42] (15035) Auto-excluding **/node_modules
2025-05-20 09:26:42.066 [info] [Info  - 09:26:42] (15035) Auto-excluding **/__pycache__
2025-05-20 09:26:42.067 [info] [Info  - 09:26:42] (15035) Auto-excluding **/.*
2025-05-20 09:26:42.067 [info] [Info  - 09:26:42] (15035) Assuming Python version 3.13.3.final.0
2025-05-20 09:26:42.067 [info] [Info  - 09:26:42] (15035) Found 1 source file
2025-05-20 09:26:42.338 [info] [Info  - 09:26:42] (15035) BG: Priority queue background worker(2) root directory: file:///Users/marbaced/.vscode/extensions/ms-python.vscode-pylance-2025.5.1/dist
2025-05-20 09:26:42.344 [info] [Info  - 09:26:42] (15035) BG: Priority queue background worker(2) started
2025-05-20 09:26:53.463 [info] [Info  - 09:26:53] (15035) Loading pyproject.toml file at /Users/marbaced/tmp/uv-test/demo-bug/pyproject.toml
2025-05-20 09:26:53.463 [info] [Info  - 09:26:53] (15035) Pyproject file "/Users/marbaced/tmp/uv-test/demo-bug/pyproject.toml" has no "[tool.pyright]" section.
2025-05-20 09:26:53.463 [info] [Info  - 09:26:53] (15035) Setting environmentName for service "demo-bug": "3.13.3 (.venv venv)"
2025-05-20 09:26:53.463 [info] [Info  - 09:26:53] (15035) Setting pythonPath for service "demo-bug": "/Users/marbaced/tmp/uv-test/demo-bug/.venv/bin/python"
2025-05-20 09:26:53.463 [info] [Info  - 09:26:53] (15035) No include entries specified; assuming /Users/marbaced/tmp/uv-test/demo-bug
2025-05-20 09:26:53.463 [info] [Info  - 09:26:53] (15035) Auto-excluding **/node_modules
2025-05-20 09:26:53.463 [info] [Info  - 09:26:53] (15035) Auto-excluding **/__pycache__
2025-05-20 09:26:53.463 [info] [Info  - 09:26:53] (15035) Auto-excluding **/.*
2025-05-20 09:26:53.463 [info] [Info  - 09:26:53] (15035) Assuming Python version 3.13.3.final.0
2025-05-20 09:26:53.463 [info] [Info  - 09:26:53] (15035) Found 1 source file
2025-05-20 09:27:02.487 [info] [Info  - 09:27:02] (15035) BG: Indexer background runner(3) root directory: file:///Users/marbaced/.vscode/extensions/ms-python.vscode-pylance-2025.5.1/dist (index)
2025-05-20 09:27:02.487 [info] [Info  - 09:27:02] (15035) BG: Indexing(3) started
2025-05-20 09:27:03.085 [info] [Info  - 09:27:03] (15035) BG: scanned(3) 1981 files over 1 exec env
2025-05-20 09:27:07.460 [info] [Info  - 09:27:07] (15035) BG: [IDX(3)] Long operation: index execution environment file:///Users/marbaced/tmp/uv-test/demo-bug (4190ms)
2025-05-20 09:27:07.505 [info] [Info  - 09:27:07] (15035) BG: [IDX(3)] Long operation: index packages file:///Users/marbaced/tmp/uv-test/demo-bug (4247ms)
2025-05-20 09:27:07.505 [info] [Info  - 09:27:07] (15035) BG: indexed(3) 1981 files over 1 exec env
2025-05-20 09:27:07.671 [info] [Info  - 09:27:07] (15035) BG: Indexing finished(3).
2025-05-20 09:27:09.964 [info] [Info  - 09:27:09] (15035) Found 2 source files
2025-05-20 09:27:41.561 [info] [Info  - 09:27:41] (15035) BG: Indexer background runner(4) root directory: file:///Users/marbaced/.vscode/extensions/ms-python.vscode-pylance-2025.5.1/dist (refresh)
2025-05-20 09:27:41.561 [info] [Info  - 09:27:41] (15035) BG: Indexing(4) started
2025-05-20 09:27:41.561 [info] [Info  - 09:27:41] (15035) BG: Indexing finished(4).
2025-05-20 09:27:48.863 [info] (Client) Running with node: /Users/marbaced/.vscode/extensions/ms-python.vscode-pylance-2025.5.1/dist/.cache/node/node
2025-05-20 09:27:49.415 [info] (Client) Pylance async client (2025.5.1) started with python extension (2025.6.1)
2025-05-20 09:27:49.596 [info] [Info  - 09:27:49] (16987) Server root directory: file:///Users/marbaced/.vscode/extensions/ms-python.vscode-pylance-2025.5.1/dist
2025-05-20 09:27:49.596 [info] [Info  - 09:27:49] (16987) Pylance language server 2025.5.1 (pyright version 1.1.400, commit b962ffc2) starting
2025-05-20 09:27:49.600 [info] [Info  - 09:27:49] (16987) Starting service instance "demo-bug" for workspace "/Users/marbaced/tmp/uv-test/demo-bug"
2025-05-20 09:27:50.460 [info] [Info  - 09:27:50] (16987) Loading pyproject.toml file at /Users/marbaced/tmp/uv-test/demo-bug/pyproject.toml
2025-05-20 09:27:50.460 [info] [Info  - 09:27:50] (16987) Pyproject file "/Users/marbaced/tmp/uv-test/demo-bug/pyproject.toml" has no "[tool.pyright]" section.
2025-05-20 09:27:50.460 [info] [Info  - 09:27:50] (16987) Setting environmentName for service "demo-bug": "3.13.3 (.venv venv)"
2025-05-20 09:27:50.460 [info] [Info  - 09:27:50] (16987) Setting pythonPath for service "demo-bug": "/Users/marbaced/tmp/uv-test/test2/.venv/bin/python"
2025-05-20 09:27:50.460 [info] [Info  - 09:27:50] (16987) No include entries specified; assuming /Users/marbaced/tmp/uv-test/demo-bug
2025-05-20 09:27:50.460 [info] [Info  - 09:27:50] (16987) Auto-excluding **/node_modules
2025-05-20 09:27:50.460 [info] [Info  - 09:27:50] (16987) Auto-excluding **/__pycache__
2025-05-20 09:27:50.460 [info] [Info  - 09:27:50] (16987) Auto-excluding **/.*
2025-05-20 09:27:50.460 [info] [Info  - 09:27:50] (16987) Assuming Python version 3.13.3.final.0
2025-05-20 09:27:50.460 [info] [Info  - 09:27:50] (16987) Found 2 source files
2025-05-20 09:27:50.462 [info] [Info  - 09:27:50] (16987) Loading pyproject.toml file at /Users/marbaced/tmp/uv-test/demo-bug/pyproject.toml
2025-05-20 09:27:50.462 [info] [Info  - 09:27:50] (16987) Pyproject file "/Users/marbaced/tmp/uv-test/demo-bug/pyproject.toml" has no "[tool.pyright]" section.
2025-05-20 09:27:50.462 [info] [Info  - 09:27:50] (16987) Setting environmentName for service "demo-bug": "3.13.3 (.venv venv)"
2025-05-20 09:27:50.462 [info] [Info  - 09:27:50] (16987) Setting pythonPath for service "demo-bug": "/Users/marbaced/tmp/uv-test/test2/.venv/bin/python"
2025-05-20 09:27:50.462 [info] [Info  - 09:27:50] (16987) No include entries specified; assuming /Users/marbaced/tmp/uv-test/demo-bug
2025-05-20 09:27:50.462 [info] [Info  - 09:27:50] (16987) Auto-excluding **/node_modules
2025-05-20 09:27:50.462 [info] [Info  - 09:27:50] (16987) Auto-excluding **/__pycache__
2025-05-20 09:27:50.462 [info] [Info  - 09:27:50] (16987) Auto-excluding **/.*
2025-05-20 09:27:50.462 [info] [Info  - 09:27:50] (16987) Assuming Python version 3.13.3.final.0
2025-05-20 09:27:50.462 [info] [Info  - 09:27:50] (16987) Found 2 source files
2025-05-20 09:27:50.465 [info] [Info  - 09:27:50] (16987) BG: Priority queue background worker(2) root directory: file:///Users/marbaced/.vscode/extensions/ms-python.vscode-pylance-2025.5.1/dist
2025-05-20 09:27:50.465 [info] [Info  - 09:27:50] (16987) BG: Priority queue background worker(2) started
2025-05-20 09:27:50.465 [info] [Info  - 09:27:50] (16987) BG: Indexer background runner(3) root directory: file:///Users/marbaced/.vscode/extensions/ms-python.vscode-pylance-2025.5.1/dist (index)
2025-05-20 09:27:50.467 [info] [Info  - 09:27:50] (16987) BG: Indexing(3) started
2025-05-20 09:27:50.717 [info] [Info  - 09:27:50] (16987) BG: scanned(3) 1984 files over 1 exec env
2025-05-20 09:27:51.092 [info] [Info  - 09:27:51] (16987) BG: indexed(3) 1984 files over 1 exec env
2025-05-20 09:27:51.243 [info] [Info  - 09:27:51] (16987) BG: Indexing finished(3).

System Info
Item Value
CPUs Apple M1 Max (10 x 2400)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) 2, 4, 14
Memory (System) 32.00GB (0.10GB free)
Process Argv --crash-reporter-id a8977bc7-df5e-4672-90cc-bfa2d2729921 --crash-reporter-id a8977bc7-df5e-4672-90cc-bfa2d2729921
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
binariesv615:30325510
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dwnewjupyter:31046869
pythonrstrctxt:31112756
nativeloc2:31192216
5fd0e150:31155592
dwcopilot:31170013
6074i472:31201624
dwoutputs:31242946
customenabled:31248079
9064b325:31222308
copilot_t_ci:31222730
e5gg6876:31282496
pythoneinst12:31285622
bgtreat:31268568
4gafe986:31271826
31787653:31262186
3e8i5726:31271747
996jf627:31283433
pythonrdcb7cf:31296842
usemplatestapi:31297334
7bj51361:31289155
747dc170:31275177
aj496949:31278748
aj953862:31281341
generatesymbolt:31295002
convertfstringf:31295003
gendocf:31295004

BlackDark avatar May 20 '25 09:05 BlackDark

editable install is considered as 3rd party package. so it won't treat it same as user file for auto/add imports.

see this https://github.com/microsoft/pylance-release/blob/main/docs/settings/python_analysis_packageIndexDepths.md on how to adjust default indexing behavior for 3rd party libaries.

heejaechang avatar May 20 '25 17:05 heejaechang

Hi @BlackDark , I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.


Potentially Related Issues:

  • Enable Pylance to recognize uv editable installs – Explains that uv’s dynamic editable installs aren’t recognized by default. #6353
  • How to make Pylance recognize packages installed in editable mode? – Discusses missing import errors with editable installs and links to installation instructions. #6923
  • Auto-import completions not triggering despite proper indexing with poetry2.0 and python3.13 – Covers similar auto-import issues in different installation contexts. #7024

Potential Workarounds:

  • Enable compatibility mode: Run the following command to install your package with compatibility settings so that Pylance can recognize the dynamic imports used by uv’s editable install:

    uv pip install --config-setting editable_mode=compat
    

The team will respond to your issue shortly. Please note this is a trial feature and may not be fully accurate. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or was incorrect, please give it a 👎. Your feedback helps us improve!

heejaechang avatar May 20 '25 20:05 heejaechang

editable install is considered as 3rd party package. so it won't treat it same as user file for auto/add imports.

see this main/docs/settings/python_analysis_packageIndexDepths.md on how to adjust default indexing behavior for 3rd party libaries.

With the packageIndexDepth did not get it to work at all. After digging through the links in the AI reply I got to the following configs:

pyproject.toml

[project]
    name = "demo-bug"
    version = "0.1.0"
    description = "Add your description here"
    readme = "README.md"
    requires-python = ">=3.13"
    dependencies = []

    [project.scripts]
        demo-bug = "demo_bug:main"

[build-system]
    build-backend = "hatchling.build"
    requires = ["hatchling"]

# https://hatch.pypa.io/1.12/config/build/#dev-mode
# https://microsoft.github.io/pyright/#/import-resolution?id=editable-installs
# requires package "editables"
[tool.hatch.build]
    dev-mode-exact = true

[dependency-groups]
dev = [
    "editables>=0.5",
]

Which creates this:

Image

And now i get completions. Is this the or a correct way to address this issue or is it not the best way to do this?

BlackDark avatar May 21 '25 11:05 BlackDark

@rchiodo is this your editable install feature working?

heejaechang avatar May 21 '25 17:05 heejaechang

Yeah could be. The easiest way to tell is if it doesn't work with 3.12. Editable install support requires 3.13.

rchiodo avatar May 21 '25 17:05 rchiodo

Tested with 3.12:

Image Image

BlackDark avatar May 22 '25 08:05 BlackDark

found the bug. will be fixed in next release.

heejaechang avatar May 22 '25 09:05 heejaechang

This issue has been fixed in prerelease version 2025.5.101, which we've just released. You can find the changelog here: CHANGELOG.md

debonte avatar Jun 03 '25 22:06 debonte

Tested with the same setup and still no completion support. Of course installed the prerelease version of pylance addon.

[project]
    name = "demo-bug"
    version = "0.1.0"
    description = "Add your description here"
    readme = "README.md"
    authors = [{ name = "changeme", email = "changeme" }]
    requires-python = ">=3.12"
    dependencies = []

    [project.scripts]
        demo-bug = "demo_bug:main"

[build-system]
    build-backend = "hatchling.build"
    requires = ["hatchling"]

# works when those are enabled
    # # https://hatch.pypa.io/1.12/config/build/#dev-mode
    # # https://microsoft.github.io/pyright/#/import-resolution?id=editable-installs
    # # requires package "editables"
    # [tool.hatch.build]
    #     dev-mode-exact = true

    # [dependency-groups]
    #     dev = ["editables>=0.5"]
Image

Following things tested:

  • python3.12 -> not working
  • python3.13 -> not working
  • config in vscode is enabled for edtiable installs support
  • still only works if I activate the commented lines in the toml for dev-mode-exact

Question: is this as expected or still something fishy?

BlackDark avatar Jun 04 '25 09:06 BlackDark

I have the exact same issue as @BlackDark described in here. The issue persists with the pre-release pylance 2025.5.101 version.

dainmik avatar Jun 09 '25 16:06 dainmik

Yeah I'm not sure this is fixed either:

Image

rchiodo avatar Jun 09 '25 16:06 rchiodo

I am probably running into the same issue.

I have a project structure like this:

.
├── apps/
│   └── qwe-web/
│       └── __init__.py
└── components/
    └── flags/
        └── src/
            └── flags/
                └── __init__.py

I'm importing the "components" e.g. "flags" as local packages.

When I build the package as editable via:

[build-system]
requires = ["uv_build>=0.7.19,<0.8.0"]
build-backend = "uv_build"

then I can not get import completions at all, no matter what I configure in python.analysis.extraPaths.

When instead of the build-system I set:

[tool.uv]
package = false

then it will build a "virtual" (which is not an option) and then I can get import completions but they are wrong.

In my settings.json I have:

"python.analysis.extraPaths": [
    "components/*/src",
],
"python.analysis.include": [
    "components/**",
],

but the import completion suggestions components.flags.src.flags. I expected to get a completion for flags.

When I set

"python.analysis.extraPaths": [
    "components/flags/src",
],

then the import completion works as expected. But we have a long list of components. It's not acceptable having to manually maintain this list of extraPaths. It should work via wildcards.

Now I'm stuck. How to get this to work? Is this the same bug described here?

Spenhouet avatar Jul 07 '25 13:07 Spenhouet

so, no auto import in completion, but how about from code actions?

heejaechang avatar Jul 07 '25 18:07 heejaechang

hmm.. it works for me.

Image

anyway, it sounds like we want to improve our support on editable installs.

heejaechang avatar Jul 07 '25 18:07 heejaechang

extra path doesn't support wildcard such as * unlike include/exclude

heejaechang avatar Jul 07 '25 19:07 heejaechang

opened issue - https://github.com/microsoft/pylance-release/issues/7396 and https://github.com/microsoft/pylance-release/issues/7397

heejaechang avatar Jul 07 '25 19:07 heejaechang

@BlackDark can you actually just zip up the folder and provide us the zip here? that will make it easier for us to take a look? since you already have repro steps?

heejaechang avatar Jul 07 '25 19:07 heejaechang

@heejaechang My code is already a test repo. I ZIPed that for you.

Reproduction

  1. Download and open in VS Code: pylance-bug-7242.zip
  2. Execute VS code Task "Install Dependencies"
  3. Open apps/qwe-web/main.py
  4. In Line 26 feature is missing an import
  5. Open the auto import completion

Expected Behavior

The import completion shows that feature can be imported from the flags package

Actual Behavior

Image

Additional Context

Opening the import completions sometimes only shows

No suggestions.

When opening them multiple times it starts showing suggestions (just not the right ones).

Environment

Pylance version: 2025.6.2 OS and version: Windows 11 with WSL and Ubuntu 20.04 Python version: 3.10 and 3.13.5 via uv

Spenhouet avatar Jul 08 '25 05:07 Spenhouet

@BlackDark can you actually just zip up the folder and provide us the zip here? that will make it easier for us to take a look? since you already have repro steps?

@heejaechang Sure here is the repo: https://github.com/BlackDark/pylance-release-bug-7242 Changed the to be imported name to be save that no other equally named exports exist :D

BlackDark avatar Jul 10 '25 07:07 BlackDark