-
Notifications
You must be signed in to change notification settings - Fork 767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'module' is not Accessed Pylance(Pylance is greyed out) #757
Comments
Edit 1: While importing the module 'wget', the exact same thing happens. So does this mean that it happens with such type of web modules? |
This isn't a bug. The warning is telling you that the source code for this module can't be resolved within your configured Python environment. It is likely that either your configuration is wrong or the module isn't installed in that environment. If you don't care about this warning, you can disable it in the settings or configuration file. |
And the reason it's grayed out is because no other code in your source file is referring to |
But how can you say that it is not installed in that environment when running the application and even using the module dosent give any error. And I meant that the word |
I guess I should not ask this... But why did you transfer this issue? |
Pylance is greyed out because Pylance is the reporter of the error. With regard to the unresolved import warning, please take a look at the trouble shooting guide: https://github.com/microsoft/pylance-release/blob/main/TROUBLESHOOTING.md#unresolved-import-warnings |
Ok..that explains it. Thanks @judej |
By the way could you tell me what more info you need? I would be happy to help you... Because you added the |
Our issue template typically asks for logs; you may have selected the "question" which is more discussion based. I'd be interested in seeing some trace logs to see what paths are being used and what files are analyzed. https://github.com/microsoft/pylance-release/blob/main/TROUBLESHOOTING.md#filing-an-issue mirrors the template instructions. |
Update - The issue was that I had python 3.7 selected in VSCode as my default interpreter but my os's default interpreter was conda 3.8.3 so all of my packages were installed there. But since Py 3.7 was selected in VSCode, Pylance thought it was not installed since it was installed for conda 3.8.3 and were not for py 3.7. But due to some odd reason running it with 3.7 didn't give any error and was able to use the modules. But I dont know why Pylance does this when I am importing a local file. |
@erictraut was actually correct in his 2nd comment |
Your original issue was about requests, which isn't a local module (it'd be an installed package). You're now mentioning a local import, can you describe this setup at all? Are you assuming some |
Ok, let me explain. Terms used: First I was trying to import requests, wget and some more modules. But it showed this error. Now few days back I just found out that inside VSCode my python interpreter was selected as Py3.7. But conda3.8.3 was my windows default interpreter. And thus all modules installed using pip were installed there. But PyLance tried to find in Py3.7 and they were not present. But the scripts never showed an error because when I was executing them through the terminal, they actually getting executed in Conda3.8.3. So when i changed my interpreter from py3.7 to conda3.8.3 in vscode all those errors were gone. And that fixed it. But now if I try to import a local file, pylance shows the error. Executing it doesn't give any error. And workd fine. But Pylance Shows the error. Hope this helps you. So could you fix so that importing local modules doesn't give an error. And also, PyLance says, this is a warning not an error. If you want I can attach a screenshot. Not using an virtual envirionment A suggestion - could you make the warning underlines yellow instead of green, that would be better. Since, green kind of means there are no issue. |
Don't know why everything became a "h1"? |
Pylance respects the interpreter chosen by the Python extension; if you have the wrong interpreter selected then we can't really do anything about that. We want to show import resolution messages as they significantly impact the analysis. If you really don't care about import warnings, you can use diagnosticSeverityOverrides and silence them. This to me is a bad idea, as it means all of the info you're working with is silently wrong. For local modules, your project layout may mean you need to set extraPaths: https://github.com/microsoft/pylance-release/blob/main/TROUBLESHOOTING.md#common-questions-and-issues RE: h1, github issues are markdown, and putting |
Thanks for the edit... yeah i know the interpreter was my bad, sorry. But I don't know about the local modules. I can set extraPaths, but previously I never had to that. So I said. And the warnings are yellow, they are green because of my theme. And I used diagnosticSeverityOverrirdes and set it to information. that way it doesn't show a warning and I still get the info. Thanks. But could you make it so that I don't need to set extraPath for local modules. |
The thing I'm curious about is "previously I never had to that"; previously meaning what? With a previous version of Pylance? With another language server setting? In another editor? |
"previously I never had to do that" means with another language server. That is with the default Python extension from Microsoft. |
I see. The previous default is Jedi, which has a pretty loose/forgiving import resolution system that favors resolving modules rather than erroring when they may not actually work at runtime. For local stuff, Pylance's behavior matches MPLS and other analyses that are more strict and try to inform of these issues. I don't know that we're likely to try and change that behavior, as we try to be as spec-compliant as possible (even if some projects require some extra configuration; most do not). The troubleshooting docs do describe this "import not resolved" message as much as possible for this reason. What'd be most helpful is a description of your repo layout, in case it's something we can attempt to detect or handle through other means. |
What do you mean by repo layout? the file structure or hierarchy? I don't know what the default one is? But I installed it from extension marketplace, named Python and author Microsoft. |
The folder layout, and how the files import each other. I'm talking the languageServer setting; Pylance is an option you had to configure to enable. If unset, that means jedi. |
Re: I didn't configure Pylance manually I just installed it from the extension store. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
any updates?? |
We are currently exploring ways in which we can improve our import resolution, or at least provide more guidance to fixing it. In your case, I did suggest extraPaths to mark extra import roots (which is our current suggestion) and we don't have any other guidance for when a project like this imports with unclear semantics (see also #253). If there are updates, we'll put them here, but I'm fairly certain what you're seeing is a part of our current design and requires you to set extraPaths as is hinted in our troubleshooting docs. |
ok... and will this issue be closed, since it is kind of resolved?? |
If you mean that it's resolved now with extraPaths, then sure, we can close this issue. |
ok then, close it... thanks |
I just saw this today
|
Yes, relative imports don't need paths to be able to resolve, as they know where they're relative to (the current module's folder). Using relative imports bypasses the problem. I'm not sure why I didn't close this issue after you asked for it, oops. #68 and #253 largely supersede this issue, in any case. |
Alright, thanks! |
please i can't seem to solve this part. > State the environment where your code is running; i.e. Python version, the virtual environment type, etc. |
I can't understnad what you cant resolve? |
I can seem to understand how and where to include the requirements.txt file
after selecting "Python Language Server" I'm confused sir.
…On Tue, Jul 6, 2021, 11:29 PyBash ***@***.***> wrote:
please i can't seem to solve this part. >
State the environment where your code is running; i.e. Python version, the
virtual environment type, etc.
If using a virtual environment, please include the requirements.txt file.
If working with a conda environment, attach the environment.yml file.
A code example (or any other additional information) we can use to
reproduce the issue.
I can't understnad what you cant resolve?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#757 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APT6FEPRBOQDHKTKENEGJYDTWLLHFANCNFSM4VEP2FKQ>
.
|
@jakebailey Could you please help @Macanthony7 ? |
@Macanthony7 I don't think your issue is related to this one; can you please file a new issue and fill out the bug report template? (The template you appear to be quoting isn't ours.) |
"Not accessed" is a visual indicator that says you haven't used the import, not that it didn't resolve or that your code won't run. The "fix" is either to remove the import or to use it, but this is only a visual indicator. |
You need to write |
ok, thanks. It worked |
Hey, I had this same problem. For others that are more visual learners, I followed the steps in this video https://www.youtube.com/watch?v=GqTsFOtZiQI I was able to resolve the issue. Thank you for posting this thread, because you were able to help me identify the problem which was the interpreter that was being used.
|
I removed a line in So I have And
Is there something I am missing? I have not configured |
The import is grayed out as a subtle way of indicating that there is no local reference to that imported symbol within the file. This is not flagged as an error (i.e. there's no red squiggle beneath it) because there are legitimate reasons why one might not reference an import locally — for example, if the intent is for the imported symbol to be re-exported to other modules. So don't think of a grayed-out statement as a "bug that needs to be fixed". Think of it instead just as a subtle hint that there is no local reference to that symbol. Sometimes that's intended and sometimes it's not. If it is intended, then ignore it. If it's not intended (e.g. it's an outdated import statement that you forgot to remove), then delete it. |
icon_id not accessed pylance |
@Aswini327, please file a new issue and include a code sample that reproduces the problem that you are seeing. |
@jakebailey @pybash1 @erictraut @debonte I am unable to access methods from sqlalchemy package. I have installed the package successfully you can see it in the below screenshot I have run the pip list command to show that sqlalchemy is installed |
@abhinay181, since this is a runtime issue, it would be better to ask the library maintainers over at the sqlalchemy repo -- https://github.com/sqlalchemy/sqlalchemy/discussions |
When I am importing the python module 'requests'. PyLance or VSCode underlines it with yellow meaning warning. It is also shown in the problems panel in the integrated terminal of vscode. Hope it gets fixed soon. I did not use the Bug Report Template because I am not sure if it is a bug.
The text was updated successfully, but these errors were encountered: