Unresolved import of local python file if main script is not at root of workspace
See original GitHub issueEnvironment data
- VS Code version: 1.47.3-1
- Extension version: v2020.7.96456
- OS and version: manjaro linux
- Python version: python 3.8 64 bit
- Value of the
python.languageServer
setting: Microsoft, Pylance
Issue:
When importing your own 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.
Steps to reproduce:
{workspacefolder}
/project1
main.py
module.py
main.py:
from module import f
y=f(3)
module.py:
def f(x):
return 2*x
Temporary solution
Select project1 as the workspacefolder or add project1 to the workspace
Issue Analytics
- State:
- Created 3 years ago
- Reactions:12
- Comments:8 (2 by maintainers)
Top Results From Across the Web
python - Pylint "unresolved import" error in Visual Studio Code
My solution · Go into the workspace folder (here workspaceRootFolder) and create a .env file · In this empty .env file, add the...
Read more >Python unresolved import: How to Solve Pylint Error
When importing your own python modules, which are in the workspace folder, but the main script is not in the root directory of...
Read more >Fix Python Unresolved Import in VSCode - LinuxPip
"Unresolved Import" is an error message produced by VSCode, not Python itself. The message simply means that VSCode cannot detect the correct ...
Read more >Not realistic warning about Python import
Under the folder, Intellisense gave the “unresolved import import” warning, but the project can run correctly. In order to eliminate these warnings, so...
Read more >User Manual - rust-analyzer
If you get an error saying No such file or directory: 'rust-analyzer' ... "workspace": run build scripts for a workspace in the workspace's...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try adding a .vscode/settings.json file to your workspace root. Inside the file:
{ "python.autoComplete.extraPaths": ["./path/to/module/code"] }
I think you can use asterisk to select all files in the “project1” folder.
+1
I am having the same issue with module imports not being resolved (module is in same directory as source file doing the import). Here’s what I see based on language server configuration:
Jedi - works fine, no errors Microsoft - unresolved-import Pylance - reportMissingImports
This started happening within the last 30-45 days I believe.
Here’s my VSC About info: