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 does not update on adding new files and packages #1443

Closed
Trance-Paradox opened this issue Jun 13, 2021 · 13 comments
Closed

Pylance does not update on adding new files and packages #1443

Trance-Paradox opened this issue Jun 13, 2021 · 13 comments
Labels
bug Something isn't working waiting for user response Requires more information from user

Comments

@Trance-Paradox
Copy link

Environment data

  • Language Server version: v2021.6.1
  • OS and version: wsl2 - ubuntu-20.04
  • Python version: 3.8.5

Expected behaviour

Pylance should update whenever I install a package or add a file in the directory. and provide autocompletion and checking

Actual behaviour

Whenever I install a package or add, change the name of a file in the project directory pylance does not update. It show import error and autocompletion and intellisense does not work. I have to reload the entire windows for pylance to recognise the file or package

Code Snippet / Additional information

import xknx

just after installing xknx using:
sudo pip3 install xknx
pylance shows error and does not gives intellisence or autocomplete
I have to restart vscode to get it to work

@judej judej added the bug Something isn't working label Jun 14, 2021
@github-actions github-actions bot removed the triage label Jun 14, 2021
@judej judej added needs investigation Could be an issue - needs investigation and removed bug Something isn't working labels Jun 14, 2021
@Trance-Paradox
Copy link
Author

Any further update on this? Anyone else facing this same issue?

@jakebailey
Copy link
Member

Is your environment located within your workspace, or outside?

If your issue is explicitly that you're installing packages to an environment outside of your workspace, then that's #923, but anything within the workspace (including adding your own code) should work as expected, which is why we didn't close it as a dupe.

It wasn't really clear from your issue which you were referring to.

@Trance-Paradox
Copy link
Author

Yes I am in the workspace when installing package in the environment. Vscode terminal automatically switches to the virtual env when opening a terminal.
Some times it occurs when I am working natively in windows and still pylance doesn't auto detect files and packages freshly added until I restart vscode

@jakebailey
Copy link
Member

That's not exactly what I mean; where is the environment itself? Did you do python -m venv .venv inside of the workspace?

Logs would be very helpful here. (Our template normally asks for this, but is mirrored here https://github.com/microsoft/pylance-release/blob/main/TROUBLESHOOTING.md#filing-an-issue)

@Trance-Paradox
Copy link
Author

Yes I did exactly that
python -m venv .venv

This the PowerShell window in vscode

(venv) PS D:\#CODE\Python> pip install fastapi
Collecting fastapi
  Downloading fastapi-0.65.2-py3-none-any.whl (51 kB)
     |████████████████████████████████| 51 kB 328 kB/s
Collecting pydantic!=1.7,!=1.7.1,!=1.7.2,!=1.7.3,!=1.8,!=1.8.1,<2.0.0,>=1.6.2
  Downloading pydantic-1.8.2-cp39-cp39-win_amd64.whl (1.9 MB)
     |████████████████████████████████| 1.9 MB 656 kB/s
Collecting starlette==0.14.2
  Using cached starlette-0.14.2-py3-none-any.whl (60 kB)
Collecting typing-extensions>=3.7.4.3
  Downloading typing_extensions-3.10.0.0-py3-none-any.whl (26 kB)
Installing collected packages: typing-extensions, starlette, pydantic, fastapi
Successfully installed fastapi-0.65.2 pydantic-1.8.2 starlette-0.14.2 typing-extensions-3.10.0.0
(venv) PS D:\#CODE\Python> python
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import fastapi
>>> 

Here is the pylance error

{
	"resource": "/D:/#CODE/Python/main.py",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": {
		"value": "reportMissingImports",
		"target": {
			"$mid": 1,
			"external": "https://github.com/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md#diagnostic-severity-rules",
			"path": "/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md",
			"scheme": "https",
			"authority": "github.com",
			"fragment": "diagnostic-severity-rules"
		}
	},
	"severity": 4,
	"message": "Import \"fastapi\" could not be resolved",
	"source": "Pylance",
	"startLineNumber": 1,
	"startColumn": 8,
	"endLineNumber": 1,
	"endColumn": 15
}

Here is the python language server output in the text file
pylance.txt

@jakebailey
Copy link
Member

Based on your logs, you don't have that new environment selected; you have your global interpreter selected.

At the bottom left, can you change the interpreter and select the one within your workspace?

@savannahostrowski savannahostrowski added waiting for user response Requires more information from user and removed needs investigation Could be an issue - needs investigation labels Jun 24, 2021
@Trance-Paradox
Copy link
Author

Thanks that solved the issue in windows.
But still I am facing problem in WSL2

The Bash Terminal output

(venv) trance_paradox@DESKTOP-OGH0AF9:/mnt/d/#CODE/WSL/Python$ pip install xknx
Collecting xknx
  Downloading xknx-0.18.7-py3-none-any.whl (147 kB)
     |████████████████████████████████| 147 kB 1.6 MB/s 
Collecting netifaces>=0.10.9
  Downloading netifaces-0.11.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl (33 kB)
Installing collected packages: netifaces, xknx
Successfully installed netifaces-0.11.0 xknx-0.18.7
(venv) trance_paradox@DESKTOP-OGH0AF9:/mnt/d/#CODE/WSL/Python$ python
Python 3.8.5 (default, May 27 2021, 13:30:53) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fastapi
>>> 

Pylance error

{
	"resource": "/mnt/d/#CODE/WSL/Python/main.py",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": {
		"value": "reportMissingImports",
		"target": {
			"$mid": 1,
			"external": "https://github.com/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md#diagnostic-severity-rules",
			"path": "/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md",
			"scheme": "https",
			"authority": "github.com",
			"fragment": "diagnostic-severity-rules"
		}
	},
	"severity": 4,
	"message": "Import \"fastapi\" could not be resolved",
	"source": "Pylance",
	"startLineNumber": 1,
	"startColumn": 8,
	"endLineNumber": 1,
	"endColumn": 15
}

The python language server log file is attached here
Pylance.txt

@heejaechang
Copy link
Contributor

heejaechang commented Jun 24, 2021

the log from WSL2 don't show your .venv in the search path. so I think you are not selecting right interpreter or there is a bug where somehow it doesn't work for you (selecting interpreter).

can you try a few times to see whether it ever works? (trying to figure out where the issue is)

@Trance-Paradox
Copy link
Author

I have the correct interpreter selected.

image

Also similar to this problem when I remove the package or file pylance doesn't give an error
image

@bschnurr bschnurr added bug Something isn't working and removed bug Something isn't working labels Jun 25, 2021
@bschnurr
Copy link
Member

After some testing this appears VSCode doesn't send us file events when using WSL with a workspace shared in windows) ie. /mnt/...

If you move your code to a WSL folder like home/ then it should work.

known issue apparently.
microsoft/vscode-remote-release#5000

if moving the folder doesn't work feel free to reopen.

@PrestonTaylor
Copy link

@bschnurr Is there some method for manual refresh of pylance? Moving directories for established projects isn't always as easy as it sounds.

@samegek
Copy link

samegek commented May 14, 2022

  1. ctrl+shift+p open command pane
  2. enter python restart lang
  3. execute
    @PrestonTaylor

@mehdi-repo
Copy link

mehdi-repo commented Sep 30, 2022

also in my case
change python Interpreter to venv
ctrl+shift+p -> type python: select Interpreter -> select Enter interpreter Path -> Brows to your .\venv\Scripts\python.exe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting for user response Requires more information from user
Projects
None yet
Development

No branches or pull requests

9 participants