I have been looking all over the internet and spent hours trying to fix this.
Summary of the issue:
- When importing a class/functions from a local module, I am getting an
Unable to import 'x' pylint (import-error)
(image #1) - Vscode is not suggesting a "quick-fix - auto import" to import an already installed library (pyngrok in this case) (image #2).
What I tried:
- Created a virtual env
- Selected the virtual env as Python interpreter in Vscode
- Installed Python-related extension: IntelliSense (Pylance)
- Installed pylint (
pip install pylint
) and selected it as a linter through Vs code - Completely uninstall/reinstall Vscode (including caches and preferences)
- Reloaded the window (
cmd+shift+p
-> Developer: Reload window) - Added
"env": {"PYTHONPATH": "${workspaceRoot}"}
to launch.json file - Added
"python.linting.enabled": true
and"python.analysis.autoImportCompletions": true
to settings.json file - Went through the Troubleshooting linting
My project structure:
my-app/
├─ venv/
├─ errors/
│ ├─ __init__.py
│ ├─ interface
├─ _app.py
├─ __init__.py
Notes:
- In the module I am importing from, I do have an
__init__.py
file - When running the code, it works just fine, so the import-error error is not an actual error
- I don't want to solve it by just ignoring the import-error in the settings
My system
- MacOS 12.5.1
- System's Python version: 3.8
- Project's Python virtual environment version: 3.8.
- Vscode Version: 1.71.0