question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unresolved import of local python file if main script is not at root of workspace

See original GitHub issue

Environment 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:closed
  • Created 3 years ago
  • Reactions:12
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
avizmarloncommented, Jan 10, 2021

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.

3reactions
rcreliacommented, Oct 13, 2020

+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:

Version: 1.50.0
Commit: 93c2f0fbf16c5a4b10e4d5f89737d9c2c25488a3
Date: 2020-10-07T06:00:00.397Z
Electron: 9.2.1
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Darwin x64 19.6.0
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found