-
Notifications
You must be signed in to change notification settings - Fork 133
Unresolved import problem for files in sub-directories in a workspace #1099
Comments
I have the very same problem. There is always either en error on the IntelliSense part or while running the code. |
The language server uses the root directory (given by VSC) as the base of the imports. If you want to change that, you can try modifying your VS Code config for the workspace to point to that directory, like: "python.autoComplete.extraPaths": ["./Work/Hospitality_Domain/Version_7"] Though it might be better to just open that folder (Version_7) when you want to work on that specific project, rather than opening the entire C: drive in VSC, which I think has some bad implications due to file watches, workspace indexing on the entire drive, etc. When running a file as a script, the Python interpreter does some extra stuff, I believe adding the script's directory to |
I'm having the exact same issue. I have a The Python Language Server should honor |
It should be noted that the The workaround is to only use vscode from a directory where the For example, in my project, I have my hardware definition file in an |
I tried your solution but it doesn't work in my case. Maybe just because I'm using my custom module for it. Since it looks like a different scenario I described everything in another issue: |
@MikhailArkhipov I am not sure whether I am using an editable install? |
I have been trying to enable Jedi to fix the problem. |
The python extension controls this; you shouldn't need to install jedi yourself. Set |
This is now documented here: https://github.com/microsoft/python-language-server/blob/master/TROUBLESHOOTING.md#unresolved-import-warnings @OllieKampo Did that configuration option work? Have you tried choosing a different directory to open (that isn't the C drive)? Happy to repopen if you're still having an issue with the configuration updated and in LS v0.3.1+. |
@jakebailey I'm not sure what I did exactly to fix it, but I followed your advice and made a new directory for my workspace that is less "deep", it only has one level of directories inside the root directory for the workspace. This seems to have somehow fixed it now without having to change the configuration options at all. I think I may have an idea what the problem was though, my old workspace was on a onedrive synced desktop, so although I thought I was opening "C:\Users\OllieKampo\Desktop..." I was actually opening "C:\Users\OllieKampo\OneDrive\Desktop...". Thanks for your help an efforts in this matter though, its really appreciated :) |
It doesn't seem very reliable. I have the path defined both in PYTHONPATH in .env and in settings.json, and all of the repositories work except the one with an underscore. Is there something special about python paths with an underscore? {
"python.autoComplete.extraPaths": [
"deps/litescope",
"deps/litex",
"deps/litex_boards",
"deps/lxsocsupport",
"deps/migen",
"deps/valentyusb"
]
} Gives me |
It sounds like you should be setting |
You shouldn't mix both extraPaths and PYTHONPATH (although we have some code in place to prevent duplicates, so it's probably not causing any issues at the moment). |
The file that it's trying to import is, in fact, |
Huh, alright. My assumption was wrong. 🙂 To confirm, are you using the daily build? Or are you still on stable? Daily contains a few fixes to the search path code that stable doesn't yet have. I'd appreciate it if you could open a new issue with trace logging enabled (and hopefully a code sample). Mainly, I'd like to see the search paths printed at the start. https://github.com/microsoft/python-language-server/blob/master/TROUBLESHOOTING.md#filing-an-issue |
I've removed I see the same behavior if I remove the |
Yes, the extension concatenates those two lists before sending them to us, so they are identical from our point of view (but setting PYTHONPATH has a much stronger execution-time impact, because Python itself reads that variable, hence why it's not the first thing we recommend). |
I'm now running the daily build. I've submitted a new issue at #1223 (comment) |
Its hard for me to explain my exact issue because I don't know all the correct terminology.
Basically if I try to import one of my own python files into another of my own python files whilst both are in the same "sub-directory" of my "main" workspace directory then I get an unresolved import problem unless I put the full file path from the "main" directory into the import in which case the python files no longer run.
Please see my example below.
Say I have files setup like this: (I've obviously omitted folders and files you don't need to see)
If I try to import Parser.py into Simulate.py as such:
import Parser
I get the unresolved import problem but the code runs just fine (as we would expect).
However if I instead put this:
import Work.Hospitality_Domain.Version_7.Parser
I do not get the unresolved import but the code does not run, (which is also what I would expect).
I'm guessing my problem is probably something simple, can anyone help?
The text was updated successfully, but these errors were encountered: