You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
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.
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'
Then in your virtual environment, navigate to the folder where those two files, create an egg and then install it.
python setup.py bdist_egg python setup.py install
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
`
""" a basic test to track down import issue """
from the_egg import eggfunc
if name == 'main':
print eggfunc.eggfunc(1, 2)
`
Note in the PROBLEMS output in Visual Studio code, you'll get:
Unable to import 'the_egg'
unresolved import 'the_egg'
Undefined variable: 'eggfunc'
But if you go to the TERMINAL and type in 'python simpletest.py' the code will work just fine.
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.
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...
Can someone just tell me how to disable this annoying green highlighting all over my code?
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.
Its hard to explain the exact issue and I don't know all the correct terminology, i'm afraid I was also a bit frustrated when I posted my original comment so apologies for that.
I'm a PhD computer science student but my masters was in mechanical engineering so I sometimes make simple mistakes with this kind of stuff which may be the issue here.
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 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).
Any ideas?
I have the very same problem. There is always either en error on the IntelliSense part or while running the code.
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, Jake Bailey (@jakebailey) , but here's all of the initial informational logs:
The entire thing, but for now I'm more concerned about what those weird \python\python\pyspark paths are. And are those logs without any extraPath configuration? ./core in that list should be making it show up in user search paths.
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.
You have that in your global user settings, or the workspace settings? The other three are fine in the user settings, but since ./core is a project-specific thing, I'd expect that to be in .vscode/settings.json.
Jake Bailey (@jakebailey) - Moving that to the workspace settings seems to have cleared everything up! I honestly didn't realize there were separate settings.... 🤦♂️
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.
I'm going through this and related issues, and for the most part you can fix things by setting extraPaths to tell us more directories to use as import roots, for example:
{
"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.
This did exactly solve the problem I was facing.
Multiple repos including python-files and vscode got somehow confused. Python-wise (debugging and such) it was working and vscode was able to follow my breakpoint. But my linter (flake8) was complaining about unresolved imports and I could not follow "Go To Definition F12" ...
After introducing this extraPaths it works like charm! :)
Activity
dmayo77 commentedon Apr 10, 2019
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
def eggfunc(x, y): return x*ysetup.py
'
#!/usr/bin/env python
a simple egg
from setuptools import setup
setup(
name="the_egg",
version="0.1",
description="A simple egg",
author='you',
author_email="[email protected]",
url="http://bogus/",
packages=[""])
'
Then in your virtual environment, navigate to the folder where those two files, create an egg and then install it.
python setup.py bdist_eggpython setup.py installNote 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
`
""" a basic test to track down import issue """
from the_egg import eggfunc
if name == 'main':
print eggfunc.eggfunc(1, 2)
`
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.
dmayo77 commentedon Apr 10, 2019
Sorry about the formatting, but hopefully you get the gist.
tab-cmd commentedon Apr 15, 2019
Same happens to me on V1.33.1 and Python 2.7.10. Same output as #887
charce36 commentedon Apr 23, 2019
I have the same problem, any solution ?
jakebailey commentedon Apr 23, 2019
We don't yet support egg files (#196), so these types of imports aren't yet going to work.
zgoda-mobica commentedon Apr 24, 2019
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.
Package is installed properly, code runs fine. Normal code that does relative imports from source tree works fine too.
charce36 commentedon Apr 24, 2019
I resolved installing Ubuntu 18.04
jakebailey commentedon Apr 24, 2019
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
OllieKampo commentedon May 3, 2019
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...
Can someone just tell me how to disable this annoying green highlighting all over my code?
jakebailey commentedon May 3, 2019
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.
OllieKampo commentedon May 4, 2019
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.
Its hard to explain the exact issue and I don't know all the correct terminology, i'm afraid I was also a bit frustrated when I posted my original comment so apologies for that.
I'm a PhD computer science student but my masters was in mechanical engineering so I sometimes make simple mistakes with this kind of stuff which may be the issue here.
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 ParserI 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.ParserI do not get the unresolved import but the code does not run, (which is also what I would expect).
Any ideas?
chudytom commentedon May 18, 2019
I have the very same problem. There is always either en error on the IntelliSense part or while running the code.
OllieKampo commentedon May 18, 2019
Tomasz Chudzik (@chudytom) Yes I am unsure what this "editable install" thing is as well and whether I am using it or not?
I have not had a reply on this thread so I created a new issue https://github.com/microsoft/python-language-server/issues/1099.
chudytom commentedon May 18, 2019
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.
29 remaining items
mattlefevre commentedon Jun 20, 2019
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, Jake Bailey (@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?
jakebailey commentedon Jun 20, 2019
The entire thing, but for now I'm more concerned about what those weird
\python\python\pysparkpaths are. And are those logs without anyextraPathconfiguration?./corein that list should be making it show up in user search paths.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.
mattlefevre commentedon Jun 20, 2019
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
\pythonand\python\pysparkpaths... I'm not sure what those are either?jakebailey commentedon Jun 20, 2019
You have that in your global user settings, or the workspace settings? The other three are fine in the user settings, but since
./coreis a project-specific thing, I'd expect that to be in.vscode/settings.json.mattlefevre commentedon Jun 20, 2019
Jake Bailey (@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!
jakebailey commentedon Jul 25, 2019
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!
chiboreache commentedon Aug 30, 2019
+1
stevenlis commentedon Feb 28, 2020
Jake Bailey (@jakebailey) The issue has always been with me...

jakebailey commentedon Feb 28, 2020
Please file a new issue. This issue is 9 months old and was about unresolved imports in user code;
requestsis a third party library.larsjuetten commentedon Apr 22, 2020
This did exactly solve the problem I was facing.
Multiple repos including python-files and vscode got somehow confused. Python-wise (debugging and such) it was working and vscode was able to follow my breakpoint. But my linter (flake8) was complaining about unresolved imports and I could not follow "Go To Definition F12" ...
After introducing this
extraPathsit works like charm! :)Thx!