Skip to content
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

Pylance is not work for jupyter notebook in VScode #4742

Closed
1 of 2 tasks
mikeyau1 opened this issue Aug 13, 2023 · 28 comments
Closed
1 of 2 tasks

Pylance is not work for jupyter notebook in VScode #4742

mikeyau1 opened this issue Aug 13, 2023 · 28 comments
Assignees
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@mikeyau1
Copy link

Applies To

  • Notebooks (.ipynb files)
  • Interactive Window and/or Cell Scripts (.py files with #%% markers)

What happened?

Pylance is not stable. When I open the notebook, it works for 1-2 hours. Then, the color of variables become white, and Pylance is unable to scan error. I check some issue in GitHub (microsoft/vscode-jupyter#8374 (comment)). I try to add a new cell. but it gives nothing to jx:
image

Also, it detect a comment line as error. it also cannot show the object selector
image

VS Code Version

Version: 1.81.1 (user setup) Commit: 6c3e3dba23e8fadc360aed75ce363ba185c49794 Date: 2023-08-09T22:22:42.175Z Electron: 22.3.18 ElectronBuildId: 22689846 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Windows_NT x64 10.0.19045

Jupyter Extension Version

v2023.7.1002162226

Jupyter logs

No response

Coding Language and Runtime Version

Python 3.11.0

Language Extension Version (if applicable)

Pylance: v2023.8.20

Anaconda Version (if applicable)

2023.07

Running Jupyter locally or remotely?

N/A or Not sure

@mikeyau1 mikeyau1 added the bug Something isn't working label Aug 13, 2023
@FlorinAndrei
Copy link

FlorinAndrei commented Aug 17, 2023

I believe I have the same problem.

Syntax highlighting tends to disappear if I scroll quickly up through a notebook. Any sufficiently large notebook will do - e.g. I have one with 7 cells, one of the cells makes a matplotlib graph. I've attached it here to help troubleshooting, but it happens with all notebooks I'm using.

fourier.zip

I have to close the notebook, close the folder, re-open the folder, and reload the notebook to fix syntax highlighting and contextual help. It's quite disruptive to my work.

I have the latest versions of everything VSCode. I have Python 3.11.4, and the latest relevant Python modules. No Anaconda, no venv.

I run Jupyter remotely via the ssh extension. Laptop runs Win10, remote dev machine runs Ubuntu 22.04.

@yehaixuan4428
Copy link

I have the same problem. When Pylance does not work in the notebook, it seems that it still works in .py files opened in other tabs. ctrl+shift+p and "clear cache and reopen window" can fix the syntax issue in the notebook, but it is really annoying and cells need to re-run.

@debonte debonte transferred this issue from microsoft/vscode-jupyter Aug 21, 2023
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Aug 21, 2023
@debonte
Copy link
Contributor

debonte commented Aug 21, 2023

Possibly related to #4733 and #4685

@videogameplayer909
Copy link

Just chipping in, same issue here. Python 3.9 in vscode, no conda or other env. Pylance works flawlessly in native .py files, but has zero presence in ipynb files. All ran locally.

@renanklehm
Copy link

Same issue, Pylance does work in Jupyter VSCode, but sometimes it just stops working and everything breaks, as a side note, I'm also using GitHub Copilot, and it seems that when Pylance stops working so does Copilot, it starts spiting no-sense code that does not relate to my work.

I've tried disabling Copilot to see if it is some sort of incompatibility, but Pylance still breaks if I scroll too fast or change something abruptly in the notebook.

@FlorinAndrei
Copy link

Any known workarounds? This bug makes VSCode nearly unusable for me.

@debonte
Copy link
Contributor

debonte commented Aug 22, 2023

If this is the same as #4733, I believe you could work around this by rolling back to 2023.5.40 or earlier.

Note that despite the word "crash" in the issue title, the underlying issue can cause all semantic highlighting, hovering, etc to break and you won't hit a Pylance crash until you attempt to add/remove/reorder cells.

@JustinSmith66
Copy link

I am having the exact same issue (as described in microsoft/vscode#190981 (comment))

But i know many other people have been having similar issues for what seems a while (see https://stackoverflow.com/questions/59775038/visual-studio-code-syntax-highlighting-not-working#:~:text=In%20my%20case%20I%20needed,as%20source%20for%20the%20problem.) im really not sure about the fix. I have also done everything to try fix this issue from reinstalling to formatting my pc (i did that for other reasons too).

i used to find when my Python notebook got really large with lots of figures then the color syntax highlighting broke. Now it seems it just breaks after having the notebook open for a few minutes or it just breaks randomly.

@jzazo
Copy link

jzazo commented Aug 23, 2023

Just wanted to mention the issue is not only with jupyter notebooks or interactive python, but happens in every python module.

@mikeyau1
Copy link
Author

mikeyau1 commented Aug 23, 2023

I would like to thank all of you.
Today, I tried to open the file locally, not open in folder or workplace. After some hours, Pylance still works fine.
I will keep this issue open for discussion and keep monitoring the issue of Pylance. It seems a lot of people who facing similar problem.

@debonte
Copy link
Contributor

debonte commented Aug 23, 2023

@mikeyau1, and others that chimed in here, it's possible that this behavior was caused by #4733 which is fixed in our latest prerelease build, 2023.8.41

Could you please all upgrade to 2023.8.41 and see if your issues are resolved?

@FlorinAndrei
Copy link

FlorinAndrei commented Aug 24, 2023

2023.5.40 appears to work well, I've used it for maybe 2 - 3 hours today on a large notebook without any problem.

2023.8.41 pre-release worked fine for about 30 min on the same large notebook, but after that again I lost syntax highlighting and tab completion. It seems to last a bit longer than the most recent stable release, but this is based on only one try.

The notebook is a fork of this one below, but with many edits by me (lots of graphics):

https://www.kaggle.com/code/filterjoe/time-series-bonus-lesson-unofficial

Dataset:

https://www.kaggle.com/competitions/store-sales-time-series-forecasting/data

@renanklehm
Copy link

Indeed downgrading to 2023.5.40 worked! Thank you!

@jzazo
Copy link

jzazo commented Aug 24, 2023

I agree, 2023.5.40 appeared to be working fine on this matter and 2023.8.41 stopped working at some point.

@debonte
Copy link
Contributor

debonte commented Aug 26, 2023

@mikeyau1, when you see this issue, if you add/delete/reorder a cell, do you see Pylance crash with an error similar to this?

2023-08-26 09:07:01.700 [info] Error: Debug Failure. False expression: Chained file path undefined doesn't match cellFilePaths c:\temp\temp\4685repro_3\test.ipynb:pylance-notebook-cell:W3sZmlsZQ==.py
    at _0x35bbe7 (c:\Users\erikd\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.41\dist\server.bundle.js:1:1025282)
    at c:\Users\erikd\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.41\dist\server.bundle.js:1:1032550
    at _0x114e49.<computed> (c:\Users\erikd\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.41\dist\server.bundle.js:1:1032582)
    at _0x4600bc._onDidChangeNotebookDocumentAsync (c:\Users\erikd\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.41\dist\server.bundle.js:1:1010710)

@mikeyau1
Copy link
Author

mikeyau1 commented Aug 26, 2023

@debonte I hit the same error again by opening a folder like #4733.

How can I see the log which related to the pylance because I see some error in OUTPUT of Extension Host page? But I am not sure it is Pylance related. My environment setting and VS Code version is the same as beginning. I did not update to 2023.8.41.

image

@debonte
Copy link
Contributor

debonte commented Aug 26, 2023

Change the combo box at the top right of the Output pane from "Extension Host" to "Python Language Server"

image

@mikeyau1
Copy link
Author

I got the similar message

2023-08-27 00:51:38.463 [info] [Info  - 12:51:38 AM] (15936) Pylance language server 2023.8.40 (pyright 03f79a81) starting
2023-08-27 00:51:38.464 [info] [Info  - 12:51:38 AM] (15936) Server root directory: c:\Users\user\.vscode\extensions\ms-python.vscode-pylance-2023.8.40\dist
2023-08-27 00:51:38.471 [info] [Info  - 12:51:38 AM] (15936) Starting service instance "FinancialDataAnalyst"
2023-08-27 00:51:38.528 [info] [Info  - 12:51:38 AM] (15936) Setting pythonPath for service "FinancialDataAnalyst": "C:\Python311\python.exe"
2023-08-27 00:51:38.528 [info] [Warn  - 12:51:38 AM] (15936) stubPath e:\Desktop\Program\Python\FinancialDataAnalyst\FinancialDataAnalyst\typings is not a valid directory.
2023-08-27 00:51:38.595 [info] [Info  - 12:51:38 AM] (15936) Assuming Python version 3.11
2023-08-27 00:51:38.750 [info] [Info  - 12:51:38 AM] (15936) Found 1 source file
2023-08-27 00:51:38.838 [info] [Info  - 12:51:38 AM] (15936) Starting service instance "FinancialDataAnalyst"
2023-08-27 00:51:38.853 [info] [Info  - 12:51:38 AM] (15936) Setting pythonPath for service "FinancialDataAnalyst": "c:\Python311\python.exe"
2023-08-27 00:51:38.853 [info] [Warn  - 12:51:38 AM] (15936) stubPath e:\Desktop\Program\Python\FinancialDataAnalyst\FinancialDataAnalyst\typings is not a valid directory.
2023-08-27 00:51:38.930 [info] [Info  - 12:51:38 AM] (15936) Assuming Python version 3.11
2023-08-27 00:51:39.075 [info] [Info  - 12:51:39 AM] (15936) Found 1 source file
2023-08-27 00:51:43.779 [info] [Info  - 12:51:43 AM] (15936) [IDX(3)] Long operation: index execution environment e:\Desktop\Program\Python\FinancialDataAnalyst\FinancialDataAnalyst (2817ms)
2023-08-27 00:51:43.780 [info] [Info  - 12:51:43 AM] (15936) [IDX(3)] Long operation: index packages e:\Desktop\Program\Python\FinancialDataAnalyst\FinancialDataAnalyst (2841ms)
2023-08-27 00:52:19.585 [info] [Info  - 12:52:19 AM] (15936) Starting service instance "FinancialDataAnalyst"
2023-08-27 00:52:19.606 [info] [Info  - 12:52:19 AM] (15936) Setting pythonPath for service "FinancialDataAnalyst": "c:\Python311\python.exe"
2023-08-27 00:52:19.607 [info] [Warn  - 12:52:19 AM] (15936) stubPath e:\Desktop\Program\Python\FinancialDataAnalyst\FinancialDataAnalyst\typings is not a valid directory.
2023-08-27 00:52:19.696 [info] [Info  - 12:52:19 AM] (15936) Assuming Python version 3.11
2023-08-27 00:52:19.841 [info] [Info  - 12:52:19 AM] (15936) Found 1 source file
2023-08-27 00:53:45.898 [info] [Info  - 12:53:45 AM] (15936) [IDX(5)] Long operation: index execution environment e:\Desktop\Program\Python\FinancialDataAnalyst\FinancialDataAnalyst (2785ms)
2023-08-27 00:53:45.899 [info] [Info  - 12:53:45 AM] (15936) [IDX(5)] Long operation: index packages e:\Desktop\Program\Python\FinancialDataAnalyst\FinancialDataAnalyst (2804ms)
2023-08-27 00:53:52.071 [info] Error: Debug Failure. False expression: Chained file path undefined doesn't match cellFilePaths e:\Desktop\Program\Python\FinancialDataAnalyst\FinancialDataAnalyst\FinancialDataAnalyst.ipynb:pylance-notebook-cell:X24sZmlsZQ==.py
    at _0x4ba240 (c:\Users\user\.vscode\extensions\ms-python.vscode-pylance-2023.8.40\dist\server.bundle.js:1:900729)
    at c:\Users\user\.vscode\extensions\ms-python.vscode-pylance-2023.8.40\dist\server.bundle.js:1:907846
    at _0x2599f4.<computed> (c:\Users\user\.vscode\extensions\ms-python.vscode-pylance-2023.8.40\dist\server.bundle.js:1:907878)
    at _0x872478._onDidChangeNotebookDocumentAsync (c:\Users\user\.vscode\extensions\ms-python.vscode-pylance-2023.8.40\dist\server.bundle.js:1:886358)


@amirhosss
Copy link

@debonte Yes, I get the exact same error on my linux desktop.

@debonte
Copy link
Contributor

debonte commented Aug 27, 2023

Ok, then this is a duplicate of #4685. Note that there are two stages to this bug. First you lose language server functionality (ex. hover, semantic highlighting) as you described above and then if you change the structure of an affected notebook Pylance will crash with the Chained file path...doesn't match cellFilePaths error.

So far I've found two ways that this problem can happen. One is described in #4733 and was fixed in 2023.8.41. The other is described in #4685 (comment), and I expect to be fixed in our next prerelease build.

@debonte debonte closed this as completed Aug 27, 2023
@debonte debonte added duplicate This issue or pull request already exists and removed needs repro Issue has not been reproduced yet labels Aug 27, 2023
@sayedabdallah
Copy link

I am still facing the same issue on 2024-July. I have vscode updated to latest version and I am using Ubuntu

@rchiodo
Copy link
Contributor

rchiodo commented Jul 22, 2024

@sayedabdallah, can you open a new issue? Your problem is likely not related to this and we'd need logs and/or repro steps to fix your issue.

@sayedabdallah
Copy link

@rchiodo yes I found out that it is an issue with pyspark only and I had to install pyspark-stubs too to get it to work
Thanks 🙏

@the-rich-piana
Copy link

Still happening to me as well. But the fix from @yehaixuan4428 appears to work

@heejaechang
Copy link
Contributor

there was some notebook bug in a package we depend on. we updated that dependency on the latest pylance (104) and python extension prerelease. can you try the latest pylance/python prerelease to see whether the issue still happening.

and if it still happens, it could be better for us to track the issue if you open new issue for your issue.

@the-rich-piana
Copy link

the-rich-piana commented Aug 5, 2024

I switched to pre-release and restarted VSCode, still appears to be happening even after I select my Poetry .venv ):

Happy to provide more info. @heejaechang Thanks.

Edit: Specifically the imports are staying Import "xxx" could not be resolvedPylance

@heejaechang
Copy link
Contributor

@the-rich-piana can you open a new issue with log? so we can track it separately and see what's going on?

@the-rich-piana
Copy link

@heejaechang #6247

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests