Diagram
To fix the unresolved import error, “set workspace directory properly or check the spelling of the import statement to ensure it is correct and capitalization matters.”
This error occurs maybe because of workspace directory is not set properly.
If that is correct, then set your Python path in your workspace settings. If you work with Visual Studio Code and import any library, you will face this error: “unresolved import”.
{
"python.pythonPath": "/path/to/your/venv/bin/python",
}
Then reload the VSCode, and it will fix that error.
For the Python-specific imports, it resolves the unresolved import issue, but it won’t resolve your modules. When importing your modules, it will return the same error, and to resolve this error, use the following setting in your workspace settings .vscode/settings.json.
"python.autoComplete.extraPaths": ["./path-to-your-code"],
When importing your python modules, which are in the workspace folder, but the main script is not in the root directory of the workspace folder, the imports are unresolved.
There is an alternative way that you can use the command interface.
Type the Cmd / Ctrl + Shift + P → Python: Select Interpreter → choose the one with the packages you are looking for, and that is it.
Using .env file
You can also create a .env file in your project root folder. Then add a PYTHONPATH to it like the following code.
PYTHONPATH = path/to/your/code
And in your settings.json file, add the following code.
"python.envFile": ".env"
Then reload the VSCode, and it will fix that error.
Related posts
How to Fix No Such File Or Directory error
How to Fix ValueError: math domain error

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.
Hi Krunal,
Could you please explain where the workspace settings are so I can set this value you mentioned.
{
“python.pythonPath”: “/path/to/your/venv/bin/python”,
}