-
Notifications
You must be signed in to change notification settings - Fork 133
Python Unresolved import issue #918
Comments
How to reproduce:
Example: Create the following two files (eggfunc.py and setup.py) in the same folder somewhere deep possibly in your virtual env. (For example, my vevn was at 'c:\venv' and I put them in 'c:\venv\a\a\eggtest' eggfunc.py setup.py a simple eggfrom setuptools import setup setup( Then in your virtual environment, navigate to the folder where those two files, create an egg and then install it.
Note that the_egg-0.1-pyX.X.egg is now installed in the site_packages folder Now, in Visual Studio code, create a 'simpletest.py' file in the root of some other folder in your venv, making sure Visual Studio is setup to use that venv appropriately. simpletest.py if name == 'main': Note in the PROBLEMS output in Visual Studio code, you'll get:
But if you go to the TERMINAL and type in 'python simpletest.py' the code will work just fine. |
Sorry about the formatting, but hopefully you get the gist. |
Same happens to me on V1.33.1 and Python 2.7.10. Same output as #887 |
I have the same problem, any solution ? |
We don't yet support egg files (#196), so these types of imports aren't yet going to work. |
I have the same symptoms in test modules. Package is installed in current conda environment with pip install -e ., symbols are perfectly importable using basic REPL yet I still get unresolved import reported and none of IS functions work. import pytest
from mypkg.convert.fields import bool2s, none2empty, sq2two Package is installed properly, code runs fine. Normal code that does relative imports from source tree works fine too. |
I resolved installing Ubuntu 18.04 |
If these are all related to editable installs (I don't think they are, not completely), then we currently haven't worked that out yet either. #989 |
I also have a similar problem, if I try to import any other python file it always says "unresolved" even though when I run it it works just fine... |
https://github.com/Microsoft/python-language-server#linting-options-diagnostics
But disabling the messages won't solve the problem of the language server not finding dependencies, so the analysis will not be any better. Your issue doesn't sound the same as this issue, if it's affecting every import (and not just editable installed ones), so if you have a test project and can make a new issue, that'd be appreciated. |
Edit: Sorry I've just realised you said to make a new issue, if this is not a simple fix then I will do that, and delete this comment. Thank you for your reply Jake. 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: However if I instead put this: Any ideas? |
I have the very same problem. There is always either en error on the IntelliSense part or while running the code. |
@chudytom Yes I am unsure what this "editable install" thing is as well and whether I am using it or not? |
Greate idea. Just please fix the link because when I click on it, it doesn't redirect me properly. I had to copy it manually. |
I have the same problem, V1.34.0, python3.7.2, MacOS 10.14.5 |
I try this extension every 6 months but bugs like this are pervasive. I have disabled all 6 available linters and these kinds of squiggly line errors which aren't really errors continue to arise. I would love a way to completely disable all visual notes in vscode from the python extension. Sadly, another six months disabling the python extension entirely. |
My previous comment in the thread shows how to disable these messages: #918 (comment) If you don't want anything from the LS, you can disable any of the ones listed in our README, though note that "unresolved import" is special in that it means that the LS wasn't able to find an import, so the analysis quality will suffer (hence why we show it). I'm going to be looking into editable installs next, and a ZenHub epic which links all the issues together is here: #1139 (though I'm not sure how egg files will play into that) |
Great news! I appreciate the work you guys do, but this import issue is a deal breaker for quite a few of us, I believe. |
Still happening to me on v1.35.1 / Python 3.7 / Linux
|
The 100% usage from the python process is likely unrelated; if it happens again I'd appreciate it if you could use |
Is there any news on this? I'm having the same issue 😞 |
I'm going through this and related issues, and for the most part you can fix things by setting {
"python.autoComplete.extraPaths": [
"./src"
]
} If you have more folders, you can list them all, and things should work. However, this doesn't seem to work when a package gets installed as editable. I believe this has something to do with how the interpreter's own default search paths get modified and how we merge all of this configuration together. I'm currently just going through all of the test projects everyone has provided to get a good view on the unresolved imports first before trying to nail that one. |
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. To switch to this for testing, you can set: "python.analysis.downloadChannel": "daily" |
@jakebailey Thanks for the update on the fix! :D Is there an estimate for when this might make it to the default/stable channel? Do I need to be on an Insiders build to use the daily download channel? It'd also probably be helpful, to update microsoft/vscode-python#3840 to link here. |
Probably within a couple days. There are some changes in 0.3.0+ that we're trying to ensure aren't causing other issues. You do not need the insiders build to run the daily channel, just place the config in your settings and reload. |
@pradyunsg try the daily channel with the fix for editable installs. I've been using it for about a week and everything works nice and smooth. |
I did; I even tried adding each sub-folder to it (in a few different ways, because I was getting desperate and was willing to try anything). Here's all the stuff I added to extraPaths:
Is that formatted correctly? I know I don't need both |
Of those, I think only |
I was wondering, regarding the editable installs, if python can find those modules, why can't the language server and I need to add them to the extra paths? I can live with that, but it can get annoying if, as me, you work with a lot of editable installs and switch back and forth between editable and packaged. |
That's what I thought. I've tried both of these configurations (separately) with no luck:
|
Editable installs use pth files, which are pretty powerful (can execute any python code at startup before any user code ever runs, but usually just contain paths) and are hard to deal with from an analysis point of view. All we can do right now is ask the interpreter "what are your paths", but the interpreter tells us this editable-installed code is a site package (because that's how pth files work), hence a configuration to tell us "no, actually this is my code". I'd like to try and remove the The language server is not the interpreter. It doesn't execute the code, doesn't know if some file is supposed to be a script (and has special paths added on), can't handle most at-runtime @mattlefevre I'd appreciate it if you could enable trace logging and upload a copy of your logs. If your code is somewhere to test, that would be extremely helpful. I mainly want to see the search paths reported. |
Here's the repo I'm working on: https://github.com/mattlefevre/book-blog I briefly looking into how to enable trace logging, but all I could find is how to use the debugger in VSC (still useful, but not what I was looking for). |
@jakebailey if the main concern is people putting virtualenv in the project folders and getting confused on that, would it make sense to statically try to detect whether a path is in one? |
@mattlefevre See: https://github.com/microsoft/python-language-server/blob/master/TROUBLESHOOTING.md#filing-an-issue I'll look at that test case tomorrow and see what's going on. (Everyone who's provided test cases for the other path issues are fixed, but it's the more complicated cases where conveniently people can't share the code... 😛 ) @pradyunsg Probably, but it's a bit tough to determine what is the interpreter's path. If an editable install is performed, then it will start saying things normally outside of its own path is "interpreter". It's going to require research and a big list of cases to get that sorted out. Note that if people are writing packages and not using editable installs, then the language server is going to have no way at all of knowing that imports are relative to another directory. It might be the case that |
On a perfectly working setup (using |
I've got a crazy amount of log information at this point (yay!), and I don't think pasting it all in here would work out (the initial loading of VSC is about 3500 lines). I'm not sure exactly what you need, @jakebailey , but here's all of the initial informational logs:
Were there any other specific logs I should include here? Or did you want me to attach the entire set of initial logs as a .txt file? |
The entire thing, but for now I'm more concerned about what those weird I haven't yet had time to look at your case yet (filing other issues and making sure 0.3 is okay to go live), but will be doing so next. |
I definitely have ./core in my extraPaths. Here are the last few lines of my settings file. Is that all set up right?
As far as the |
You have that in your global user settings, or the workspace settings? The other three are fine in the user settings, but since |
@jakebailey - Moving that to the workspace settings seems to have cleared everything up! I honestly didn't realize there were separate settings.... 🤦♂️ Thank you! You're my hero! |
This issue has been stale for more than a month; I'm going to close it. If you're still having unresolved import issues, please check the docs here to see if extraPaths or PYTHONPATH are enough for you: https://github.com/microsoft/python-language-server/blob/master/TROUBLESHOOTING.md#unresolved-import-warnings If you're still having issues after trying that, please open a new issue with your case so we can look at it individually. We know there is still more work to be done when it comes to our import system (#443, #1360, others), but it's difficult to handle the varying cases all in one place. Thanks! |
+1 |
@jakebailey The issue has always been with me... |
Please file a new issue. This issue is 9 months old and was about unresolved imports in user code; |
This did exactly solve the problem I was facing. Thx! |
When pylinting a file in a big project, it appears as though libraries installed in a venv are not being discovered and thus I'm getting unresolved import issues.
Version: Visual Studio Code Version 1.33.0
Python 2.7.14 (which is what I have to use in my venv)
Sadly, I can't post a screen shot of the issues due to proprietary restrictions.
However, I am able to tab over to the Terminal window, which is pointed to my venv and open python and import each of the libraries that the Problems view indicates are problems from the linting operation without issues.
These aren't pylint errors either they are "Python(unresolved-import)" issues. Neither pytlint, pep8, or flake8 report issues with those imports.
Seems similar to microsoft/vscode-python#3840 which was flagged as being closed, but doesn't appear to be resolved, and I can't post there as that issue is locked.
Could also be simlar to #541 which is 'closed' and #887 which made me spawn this issue.
I'll see if I can reproduce in more a basic way without proprietary libraries in the venv so that it can be fixed and add here with the details.
The text was updated successfully, but these errors were encountered: