Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve Pylance "import could not be resolved" in VSCode Jupyter Notebook?

I am trying to import function query_creative inside of file query_creative.py into the notebook Notebook.ipynb. The file hierarchy is like this:

    ├───playground
    │    Notebook.ipynb
    ├───src
    ├───queries
         query_creative.py

The code I use in my notebook goes like this:

import sys
sys.path.append('..')
from src.query.query_creative import query_creative

and the thing works. However, the line with the function import is underlined by Pylance with the message: "Import could not be resolved" and when I use this function later on, it works but Pylance underlines it again. I've tried modifying the setting.json, but nothing seems to work. I thank in advance for any help!

like image 428
Sanjin Juric Fot Avatar asked Jan 20 '26 13:01

Sanjin Juric Fot


1 Answers

For me the following fixes this: make sure you have correct python environment selected as the kernel. Then press F1, type "reload" and select "Developer: Reload Window". It will restart VSCode, reopen all your files and all imports are now detected.

Sometimes, you can select the correct kernel, close your current vscode tab tab and press Ctrl+Shift+T to reopen it, which is a little bit faster. This seems to only work if you have a workspace opened.

like image 99
Ford F150 Gaming Avatar answered Jan 23 '26 06:01

Ford F150 Gaming



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!