-
Notifications
You must be signed in to change notification settings - Fork 133
Unresolved import with packages under "src" when installed as editable #1013
Comments
I don't believe editable installed packages work at the moment (#989), but I haven't yet tested to see if it had been working before and now is not. If the code is in |
Ah yes, you are correct. This seems to be related to editable installs (#989). Uninstalling the editable package in the virtualenv and reloading the language server has my autocompletes working. I didn't make the connection as I am pretty sure (anecdotal, yes) editable installs have worked fine in earlier versions. This is not a proper fix though, as this now causes the VS Code embedded linters to throw similar errors (e.g. pylint's To answer your last question about the structure: I am building a package using the packaging structure described in this blog post, which has been adopted by some popular packages such as cryptography and twisted. My main reason is because editable installs without using |
Interesting, I wouldn't have thought that doing an editable install would cause the imports to disappear if |
Yeah. It may be worth keeping this as a separate issue. I tried enabling the trace output for the language server, but nothing of interest appears in the log. I created a minimal repository which can be used to locally reproduce the issue here: https://github.com/eirikrye/vscode-1013-repro |
I can confirm also having this issue (on macOS 10.14). I'll happily do any data gathering/testing to help address this. |
I should say, the problem is there not only when you try to import from editable installs (pip install -e ...), but also when you try to import from local ("non-packaged") files. |
If you have a good reproduction we can test with, then we'd appreciate it. Many (if not all) of the currently open issues on unresolved imports are some variation of editable installs or egg imports (known issues), so something new would be great in a new issue for us to handle. |
@egabrum Are you sure that is the case? My reproduction repo above shows that local imports (with |
Good snapshot: Good search paths:
Bad snapshot: Bad search paths:
Note how the "bad" output has I think the user paths should be searched before we get to the interpreter paths, though, so maybe that would be a fix. @AlexanderSher would know better what's going on. -- An aside, but if we support A quick search shows that there doesn't seem to be an easy way to disable pth files, which we could potentially use to distinguish them and treat them differently (i.e., apply the same rules as we do for searchPaths to figure out what is user code and what is not), not that it would 100% work either, since it's possible that a pth file points to something that isn't user code but exists in the workspace. This would require more thought. EDIT: I believe that these get printed before the processing I do to classify the paths, so the difference being printed in the log is not actually where the path list ends up (but is probably related). |
@eirikrye , I haven't tried your repo but if I have 2 modules (one.py and two.py) in the same folder and I try to If I re-enable Jedi, it's all good. |
@egabrum Like this? I'm not sure exactly where the error message you're talking about ("variantIds") would be coming from, at least in your example. |
Yes, exactly. |
I think this issue is distinct from the editable install issues, then. I can't seem to make it happen, but if you have a project that does it, I'd appreciate it if you could post it somewhere and make a new issue. (The message at that hover is #955, but the import not being resolved is another issue.) |
Interestingly, I get "unresolved import 'two'" with Python 3.7.1 and 3.6.6 64-bit, but not with 2.7.13 32-bit |
Python 2.7 has different module resolution logic. Can you make a screenshot of your folder structure in VSCode? |
I have the same problem. I have created the tiniest possible repository that demonstrates the problem: https://github.com/carmenbianca/vscodesrc Just run:
And then explore the project in VSCode. Module
|
In addition to my previous post, I can reproduce this issue in the project I'm currently working on at https://github.com/fsfe/reuse-tool. It's basically the same thing: The language server cannot import |
pip's editable installs are effectively the same as |
Hi @jakebailey if I can help with testing something out, I'll gladly do so. I can see how the mixing up of these issues can be problematic from your end. |
At the moment, our current recommendation is to use the A fix to editable installs was merged in #1183 (v0.3.1+), and will be available in the daily download channel shortly (and stable likely after). To switch to this for testing, you can set: "python.analysis.downloadChannel": "daily" Inferring this information automatically is more difficult than it seems, but there is likely work that can be done on that front in the future. |
A project I am working on is structured with all its packages under a
src
folder in the project/workspace directory.I am using a local virtualenv for development (
.venv/bin/python
), and the package is installed in editable mode, meaning it should be available insys.path
for that Python interpreter.However, Visual Studio Code fails to resolve any of the imports from these packages, throwing
unresolved-import
errors and missing autocompletes.Autocomplete instead suggests importing
src.mypackage
, instead of simplymypackage
.I have tried various variations of
python.autoComplete.extraPaths
:["${workspaceFolder}/src"]
,["src"]
,["./src"]
, restarting the language server after each change, but none appear to work.I have attempted with the beta `downloadChannel as well, to no avail.
The Output tab prints the following:
This seems to suggest that the language server has detected the folder both in the Python installation's
sys.path
, as well as the configuredpython.autoComplete.extraPaths
How do I get the language server to resolve my imports properly?
The text was updated successfully, but these errors were encountered: