Having an import resolution error with pylance not recognizing packages. (Windows 10)
- Venv activated on the local directory
- Confirmed pip -list that the package is correctly installed
- Ran VS code as administrator
- Checked the package is installed in the /Lib/site-packages folder for my python installation
Receiving the error:
ModuleNotFoundError: No module named 'abc123'
Inside the file, hovering over the broken import says
"packageFoo" is not accessible
Import "packageFoo" could not be resolved Pylance
CodePudding user response:
I found many similar questions, but not this specific answer.
In vscode, locate the file dropdown on the top toolbar.
Select preferences > Settings (Ctrl )
In the search bar, search for pylance
Scroll down to Python > Analysis: Extra Paths
Click 'add item' button
Next step you need to identify the installation path for python in windows. In that path there is a 'Lib' folder. Under lib folder there is a 'site-packages' folder. This is the folder for all your pip installed packages.
For me it looked like this:
C:\Users\user_name_here\AppData\Local\Programs\Python\Python310\Lib\site-packages
Copy this path and add it as the item in the pylance vscode settings.
Additionally: You can open the 'Python > Analysis: Indexing' settings below to edit a JSON file. Here you copy and paste the same path, with extra '' - backspace escape characters. Noting there is a comma after the first entry, if it exists.
CodePudding user response:
If you have correctly installed Pylance
when you open a .py
file, this extension would be activate. Now check settings.json
file and add the following sentence:
"python.languageServer": "Default" or "Pylance"
.
It is probably that your problem is caused because Pylance
is not pointed to the path where is your library installed or another package and the error is originated (ModuleNotFoundError: No module named 'abc123'
), then you may need to verify in your settings.json
this configuration:
python.analysis.autoSearchPaths
: true
python.analysis.stubPath
:./typings
python.analysis.extraPaths
:["./folder"]
(if your project use a specific folder
)
python.analysis.autoImportCompletions
:true