-
Notifications
You must be signed in to change notification settings - Fork 769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import can not be resolved error in pylance jupyter notebook for importing .py file in same directory as notebook #3017
Comments
Me too, the same code, after updating vscode, reported such an error “Import "model_2" could not be resolved Pylance(reportMissingImports)” |
@jj-github-jj, can you search for "LSP Notebooks experiment" in the Jupyter log and tell me what that line says. It's likely either:
or
If you see |
I have exact same issue... set the python.pylanceLspNotebooksEnabled but it didn't work.... |
Setting
@laye0619 Did you make sure to set it to false, not true? |
I've already set the "python.pylanceLspNotebooksEnabled": false in my setting json file and reloaded... but seems that it was still not working.... searched the 'LSP Notebooks experiment' in Jupiter log and found that LSP Notebooks experiment was still enabled.... |
Tried setting "python.pylanceLspNotebooksEnabled": false in user\settings.json, reloaded vs code and still have cant resolve import errors. |
This issue has been fixed in version 2022.8.12, which we've just released. You can find the changelog here: CHANGELOG.md |
@heejaechang the issue is still there, though in a different form. This is my project structure:
|
@debonte solution works for me, although I do have to correct the path when running from a sibling:
I have to put this on top of the first cell.
|
The same overall issue for me. Code runs but Pylance isn't happy. It was working last week. Currently on Pylance 2022.8.31
|
Same here with a local library installed in editable mode in conda environment: the package is correctly imported and documentations are displayed for all modules in the package but not whenever I import the package in a notebook. I tried the
--> did not solved it About VS Code |
@Xabitsuki Is |
This issue has been fixed in version 2022.8.41, which we've just released. You can find the changelog here: CHANGELOG.md |
Do I still need to diable |
With the latest version of VS Code (1.71.0), Pylance 2022.9.10, the problem is still there. Only works after disabling LSP Notebooks experiment and setting the analysis path, and then restarting all the kernels, etc... |
Same for me. The issue persists. |
@MrYutz, @antonioalegria, @torext, it's likely that you are seeing #3208. We'll be shipping a fix for that in prerelease tomorrow. |
#3208 has been fixed in prerelease version 2022.9.21, which we've just released. You can find the changelog here: CHANGELOG.md |
VSCode (1.71.1) and Pylance (2022.9.21). I tried to confirm the fix, and everything works fine when I create a new workspace. However, with the workspace I have been working on, it doesn't seems to work. I restarted VSCode, I deleted all workspace settings, but no fix. Why is this happening? The current workspace is a git repo, I don't know if this matters. I also tried it with other workspaces that are git repos, and everything seems to work. UpdateI think I get the reason for the problem, but I don't know how to solve it. The situation is like
I use conda environment and I add the
from the root folder. Everything work fine in the |
I can confirm that pre-release 2022.9.21 fixed the local import issue for
me. The only action performed on my end was a reload of VS-Code in an existing workspace.
|
This still isn't fixed for me when I create a new blank unsaved Jupyter notebook via Below shows the failure in a new notebook and how it's now working in a saved notebook. Also, I keep getting double entries in the autocomplete suggestions regardless of whether I'm in a saved notebook or not: If I set
in the user settings, then both issues go away. |
@torext I am having the duplication issue again after the update. It had gone away, but now I am getting duplicate symbol suggestions, but only for native python libraries. See screenshot. dict and dict.update() show duplicates, but none of the other recommendations are duplicated. |
@elashrry, if @torext, @MrYutz, please file new issues for your recent comments. It's extremely difficult to track and discuss what you are seeing when it's posted as comments on closed issues. |
The main message of my comment was that the issue under discussion is still not fixed when opening a new notebook. Should I file a new issue for this? |
@torext, yes please. Pylance handles unsaved notebooks differently than saved notebooks. Also, I think the completion duplication issue is unrelated. It may be microsoft/vscode-jupyter#11038 as you suggested. I'm not sure. |
I can confirm this. Setting |
@svenstehle, FYI we will be removing the old notebooks implementation in the future, at which point the |
what do you mean "in the user settings". where are the user settings or how does one get to the user settings that you are referring to ? |
@dlefcoe You open the Command Palette by the keyboard shortcut: Command+Shift+P on mac and Ctrl+Shift+P on windows, then write "user settings", you should find user settings as GUI and user settings as JSON. Choose what you prefer. |
Clean cache |
Great! It works for me! |
Weird behaviour!!! |
Environment data
Code Snippet
import myfunctions as mf
#myfunctions.py in same directory as notebook
Expected behavior
hovering over mf.function() should show docstring etc
Actual behavior
no doc string since pylance reports import can not be resolved error.
Also noticed on a fresh dev machine install of vscode is actually showing the correct behavior for
one file i.e import myfunction as mf is working but in another ipynb file in the same directory opened in the same workspace at the same , import myfunction as mf does not work for pylance but
import myfunction
mf = myfunction
mf.function()
does work as expected in showing doc string for myfunction etc.
seems like workspace files are creating issues. If I open folder containing myfunction.py and the caller.ipynb after deleting any workspace files, things are working as expected. But after adding folders to workspace (a parent folder of the current folder) and saving as workspace file, pylance starts giving import can not be resolved errors.. My workaround is to delete all workspace files, open just the folder and pylance is happy
Logs
The text was updated successfully, but these errors were encountered: