0

I have been looking all over the internet and spent hours trying to fix this.

Summary of the issue:

  1. When importing a class/functions from a local module, I am getting an Unable to import 'x' pylint (import-error) (image #1)
  2. Vscode is not suggesting a "quick-fix - auto import" to import an already installed library (pyngrok in this case) (image #2). Error #1 Error #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
Tomer
  • 33
  • 3
Tomer
  • 33
  • 6
  • For the first question, please show your workspace directory structure. For the second question, according to an [issue](https://stackoverflow.com/questions/55582277/visual-studio-code-quick-fix-python) in 2019, the Python extension for VS Code currently doesn't offer any quick fixes. – MingJie-MSFT Sep 06 '22 at 06:44
  • @MingJie-MSFT Thanks. I was able to fix the first issue by simply deleting the __init__.py file from the root folder of my project. About the 2nd issue, kinda weird that they haven't fixed it since 2019, but I guess it is what it is. Thanks again. – Tomer Sep 06 '22 at 15:01

1 Answers1

0

I was able to solve the first issue by deleting the __init__.py file from the root folder of my project.

Regarding the second issue, as MingJie-MSFT commented - it is an issue from 2019.

That being said - I was able to (partially) solve it, by installing the Sourcery extension for vscode.

Tomer
  • 33
  • 6