-
Notifications
You must be signed in to change notification settings - Fork 133
unresolved imports #1085
Comments
Judging by the screenshot, this looks like a case of an import that is not rooted at the workspace root. If you have a path like |
thanks @jakebailey ! So just to understand - In order to use "Microsoft Python language server" instead of python.Jedi, I would have to redesign every python script ? |
That's not what I'm saying, no. I'm saying that we consider the "root" to be what VSC gives, which is the directory you have open. From what I can see in the screenshot (which is cut off, so I can't give you any specific help), |
@jakebailey Thanks for your time and explanation. Maybe it's the problem of my workflow then.
So I guess "module01.py" is not at the "root" of workspace but it is at the root of mainprojectfile.py, hence python works by just 'import module01' Scenario02: If I import 'projectmain' directly, instead of 'testproject' to the Workspace - it does work fine (but i will "loose" top level elements, including my .git)
Scenario03: If I would keep my original folder structure and do Scenario04: adding path to python - this would also not work for linter:
So.. either I would have to redesign my workflow or modify PYTHONPATH (or settings) for every project. |
You can set per-workspace VSC settings. Try {
"python.autoComplete.extraPaths": ["./projectmain"]
} |
Thank you, it works. |
works great! thank you! |
@jakebailey Forgive my confusion, but why is this an issue with absolute imports? Although I understand why relative imports might pose a problem (since it's possible to run into a relative import beyond the top-level package), aren't absolute imports the same regardless of where the calling script is started from? If I have
then if |
The problem with scripts is that we have no idea that any one file is going to be run as a script and have its We consider the workspace root to be the main import root. That There are ongoing issues surrounding this issue, including automatically configuring things as best possible for common structures (like a top level directory used as an import root like |
Thanks for the detailed write-up, this clarified a lot. Would it be technically feasible to add a workspace-by-workspace option to assume that |
I guess I'm not sure what you mean; could you provide an example? We already run a script with the selected interpreter to look at sys.path, but past that, it's not examined. |
Yes, certainly. In the example I gave above, Now, we cannot always assume that |
The language server already assumes that Right now, if you know that |
Wow, I have spent way too much time on fixing this issue, mark of the brainlet |
Is this solution temporary? To add the configuration for every folders is troublesome. And, pylint don't work well. Can fix this problem by other way? |
I don't see this being temporary. Every tool (LS, pylint, pytest, etc) needs to be able to know the valid import roots; no tool knows without configuration how you're going to run the code and has to make some assumption. If we start adding everything as valid import roots, then our accuracy on resolved imports is poor. It's better to not get some things and require configuration in the exceptional cases than to over-search and end up with silently broken code. |
Thank you for your explanation. |
Why doesn't vscode use my python path to give intelligent suggestions + show parameters/docs? |
@jakebailey I have an issue where I can go to the declaration of the project in one place but not in the other (and also it never gives me suggestions for project I installed myself with What should I do? e.g.
with 1 I CANNOT go to the declaration with a right click but I CAN with 2 when I go to |
This is an old closed issue. You have already opened an issue (#2088); there's no need to paste messages in multiple places. |
@tmdag commented on Thu May 02 2019
Everything was just working fine. I wanted to give it a try to suggested 'Visual Studio IntelliCode 1.1.5'. I've installed it and got some popup that I didn't read carefully, that it has to connect to Microsoft server or something, I clicked OK.
From this moment my existing python and pyqt projects are screaming with errors 'unresolved import' for local files like QtUI or anything else for that matter. Uninstalling or disabling IntelliCode did not help.
Environment data
@karrtikr commented on Thu May 02 2019
Please provide answer to the following questions,
Please inform if you are using Language server or jedi, i.e check the value of
python.jediEnabled
insettings.json
, if any such setting.Clicking OK enables Language server (
python.jediEnabled: false
), which might be your problem. To rectify that just change it totrue
or remove that setting.Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)Output from
Console
under theDeveloper Tools
panel (toggle Developer Tools on underHelp
; turn on source maps to make any tracebacks be useful by runningEnable source map support for extension debugging
)@tmdag commented on Fri May 03 2019
Enabling python.Jedi fixed the issue. That also brought back the popup
settings.json
"python.jediEnabled": false,
Output
Errors in Developer Tools
console.ts:134 [Extension Host] Python Extension: Python Extension (Error in Failed to check if file needs to be fixed, method:doesFileNeedToBeFixed): Error: ENOENT: no such file or directory, open '/home/myuser/dev/mycode/.vscode/settings.json'
@Ronkiro commented on Fri May 03 2019
An addition.
I also had the same problem (Windows 10 Enterprise), fully reinstalling VSCode (Uninstalling and removing the folders from APPDATA, user, etc) solved the issue. Had a lot of problems with language server too, they all seem solved after that.
Maybe it's a config problem, or something related to PATH.
@karrtikr commented on Tue May 14 2019
Closing as the issue seems to be solved. Please open up a fresh issue if the problem re-occurs.
@tmdag commented on Tue May 14 2019
@karrtikr,well not really, unless "Microsoft Python language server" is NOT meant to be used ??
If that is the case, can I get rid of that annoying popup that asks me to turn int back on ?
don't see really any solution, only work around which i don't think it is a solution at all :(
The text was updated successfully, but these errors were encountered: