Python Unresolved import issue
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 https://github.com/Microsoft/vscode-python/issues/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 https://github.com/Microsoft/python-language-server/issues/541 which is 'closed' and https://github.com/Microsoft/python-language-server/issues/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.
How to reproduce:
- Create an egg for a library you want to distribute (see https://mrtopf.de/en/a-small-introduction-to-python-eggs/)
- Install that library
- Attempt to import that egg in your code.
- Look at the problems reported by VS Code
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*y
setup.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_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.
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... Can someone just tell me how to disable this annoying green highlighting all over my code?
https://github.com/Microsoft/python-language-server#linting-options-diagnostics
{
"python.analysis.disabled": ["unresolved-import", "undefined-variable"]
}
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)
C:.
│ Potassco.code-workspace
│
├───.vscode
│ settings.json
│
└───Work
└───Hospitality_Domain
└───Version_7
│ Architecture.lp
│ domain_setup.lp
│ Parser.py
│ Robot_Hotel.sp
│ Simulate.py
│ SPARC.jar
│
└───__pycache__
Parser.cpython-36.pyc
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).
Any ideas?
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.ParserI 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.
@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 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.
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: https://github.com/microsoft/python-language-server/issues/918#issuecomment-489214816
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)
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
> reload windowfixes it. Confirmed (first time it was after killing a python process that was taking 100% CPU, but it seems unrelated)
The 100% usage from the python process is likely unrelated; if it happens again I'd appreciate it if you could use ps or top to find the arguments given to that script and open a new issue for us to look at (so we can figure out which module is hanging when being inspected).