basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

Import resolution in notebooks

Open Hyperthetical opened this issue 8 months ago • 3 comments

Description

I have been using basedpyright in vscode and vscodium and I have noticed that it does not correctly resolve import statements in jupyter notebooks with conda environments. If I use a .py file instead, this works perfectly with the same interpreter selected. Am I missing something obvious here?

Hyperthetical avatar Apr 20 '25 10:04 Hyperthetical

are you able to provide a minimal example? are you trying to import from other notebooks? from my understanding doing that isn't possible (but i have no experience with notebooks so i may be wrong?)

DetachHead avatar Apr 20 '25 10:04 DetachHead

Weirdly it just started working after I left vscode alone for 5 minutes. However, there are issues with numpy functions on hover Image

Hyperthetical avatar Apr 20 '25 10:04 Hyperthetical

what's the issue? i can't tell from that screenshot. i tested it and the hover text is the same in regular .py files

DetachHead avatar Apr 20 '25 10:04 DetachHead

Maybe that is a separate issue, but in my case the issue is that cross-cell import / usage doesn't resolve at all. Mind you that it's a remote - SSH connection and the jupyter kernel is not ran by vscode (I connect to it through a localhost link), so it might not actually have the needed info (e.g. venv paths) for this. Though I believe it's not an issue since it doesn't say "couldn't resolve" Image

Any help would be appreciated :)

FallenChromium avatar Jun 13 '25 13:06 FallenChromium

can you check the log by selecting "basedpyright" in the output tab and see if there are any errors?

Image

i'm not sure how remote SSH dev environments work in vscode but i suspect it probably works similar to live share,see https://github.com/DetachHead/basedpyright/issues/939#issuecomment-2526971160

DetachHead avatar Jun 14 '25 13:06 DetachHead

I too am gettign this issue in notebook. there are no errors in the output. it works in normal python files

Image

ShravanSunder avatar Jul 18 '25 20:07 ShravanSunder

It looks like you haven't imported BaseModel from pydantic, so it looks like that error is correct

DetachHead avatar Jul 19 '25 01:07 DetachHead

Or is it imported in a separate cell? Could you provide a minimal repro or the full notebook file so I can investigate

DetachHead avatar Jul 19 '25 01:07 DetachHead

in the above case with pylance, i get a option that allows me to quick fix => import pydantic

this isn't the case with basedpyright in notebooks.

i will attempt to make a repo later this week

ShravanSunder avatar Jul 23 '25 13:07 ShravanSunder

what version of basedpyright are you using? there was an issue with code actions in notebooks that was fixed in 1.30.1 (#1384)

DetachHead avatar Jul 23 '25 14:07 DetachHead

I am using basedpyright = 1.31.0

ShravanSunder avatar Jul 23 '25 14:07 ShravanSunder

Hmm, yeah I'll need a minimal repro to investigate

DetachHead avatar Jul 23 '25 22:07 DetachHead

@DetachHead i was mistaken, it was not running the environment version, it is fixed in 1.31

ShravanSunder avatar Jul 25 '25 20:07 ShravanSunder

closing this since there's not enough info about the original issue from OP. @Hyperthetical happy to reopen if you provide more details

DetachHead avatar Jul 27 '25 06:07 DetachHead