VSCode Pylance auto import only prompt for typing - python

I am using vscode python and pylance extension. Half a month ago, everything was wonderful, when I typed pandas without importing it, I can press cmd + . to show quick fixes but now I cannot. Besides, pylance says it has an auto import function, however, it only auto imports anything relates to typing package.
Should I modify pylance stubpath because now it is default to typing?

Pylance's "quick fix" and "auto import" functions are available. It displays the modules that have been used by default, especially the files in the current project have used this module.
It is recommended that you disable other unrelated extensions to avoid interference between extensions. In addition, please try to reinstall the extension "Pylance" and reload VSCode.
Reference: Auto-import doesn't work.

Had the same problem and the easy fix is to add:
"python.analysis.stubPath": "",
"python.analysis.indexing": true,
in your settings.json either in workspace or in user settings of VS Code.
More about VS Code settings here: https://code.visualstudio.com/docs/getstarted/settings

Related

VSCode doesn't 'see' Python installed modules for auto import... only manual typing for import

Pylance, and IntelliSense work fine with default modules, let's say, os or datetime or so, but I've installed aiogram (any 'custom' modules have the same issues in VScode) and use some classes from it as here
vscode doesn't see where to import it from... so they are in aiogram.types and I should manually type that from aiogram.types import InlineKeyboarMarup every time.
I've tried import magic - no changes...
Pylance has settings for auto import suggestions and as I said it works fine ONLY with default modules, no question, every installed module - get that problem.
please help, don't want to use PyCharm, hope a solution is somewhere
Add the following code(This is a hidden content) to your settings.json:
"python.analysis.packageIndexDepths": [
[
"",
2
]
]
What it basically means is ["package name", "max depth to search"]. "max depth" basically means how many dot you need to access the module you want. Deeper you go, Pylance will take more time to scan python files.
InlineKeyboarMarup is a deep method. Usually, pylance will only retrieve the methods in the first level directory.

Installed Python 3.10.2 and now my Pip installs are not being found

Everything in my code was working perfectly fine up until I decided I wanted to utilize match-case in Python. Find out its only a thing in 3.10+, so I quickly install it and change it to be the interpreter in command palette.
Then I try to run my code same as before, and I'm not sure what changed but my Keyboard import is giving me 'Import "keyboard" could not be resolved'. Issues. The same issue was actually present as well with the 'from nis import match' module.
I installed keyboard initially using 'pip install keyboard' when running my 3.9 version, and legit everything was fine. This all started after I installed 3.10 (which I did from Pythons website yes); and I did add to PATH, but I dont think that would have any impact on my imports in VScode.
Confused as heck right now, please look at my screenshots for clearest explanation of what I'm facing.
Import could not be resolved
.
Module Not Found Error
.
pip3.10 show keyboard
.
My interpreter list from command palette
Any and all help appreciated, I'm extremely confused and think I've tried it all now
New Python versions use new site-packages folders. You need to reinstall everything. This is why poetry, pipenv, or requirements.txt are used
I think the linter-like extension/whatever Pylance is is the problem. Why? Because as we've tried, pip install keyboard and pip install --upgrade keyboard just confirm that the requirement is satisfied and the latest version of keyboard is already installed.
What I did was change Pylance's settings. Yes, it's not an actual error (with the code), but Pylance's problem. It just didn't see enough files in the keyboard package to satisfy its hunger, or Microsoft was just too lazy to pass more checks and update it accordingly, because however it happened, when I tried changing the setting to display an "error" at "missing imports" for fun, it didn't show errors or the default "warning" but "none", because I had run the file before I changed it back to display an error (maybe Pylance observed that when the file was run, there was no ModuleNotFoundError, and so stopped showing the warning).
I better shut now, because the setting I changed/overrode by adding it in settings.json is:
"python.analysis.diagnosticSeverityOverrides": {"reportMissingImports":"none"}
which is in:
{
...,
...,
...,
"python.analysis.diagnosticSeverityOverrides": {"reportMissingImports":"none"}
}
Here is a list of keys like "reportMissingImports" whose values you can change. These are the allowed values for the keys in python.analysis.diagnosticSeverityOverrides:
error (red squiggle)
warning (yellow squiggle)
information (blue squiggle)
none (disables the rule)
You would want to change their values only if you want to change their behaviour.
You can find settings.json by its path or by going to the settings GUI and clicking on any "Edit in settings.json" link-like button. You can also make settings.json open instead of the GUI by default.
Now, you won't see any more warnings when you import modules and can code without being anxious about the stupid warning.
Wow, So as it turns out, a solution I tried previously, to no avail is now working to solve this bizarre issue.
Simply put, I once again went to Command Palette (Ctrl+Shft+P), and looked through my interpreters I had to see what could be wrong.
Decided to click on the 'recommended' option I assumed I had been running this whole time. Turns out I was using this 'third' option as shown in the screenshot (the one not highlighted ofcourse); and it's the reason my module installs were being found on my machine, but not by the interpreter; as such giving me errors and not running the module for the program.
Simple error, but thanks to those who did help.

VSCode/pylint reports module win32event as unresolved import when module is installed

It's a small annoyance, but, pywin32 modules get reported as unresolved imports by the python linter in VSCode.
I've got pywin32 installed, and I'm able to import the module(s) in a terminal session, and when the script runs.
My python.pythonPath is set correctly in my settings.json.
The linter just can't seem to find the modules.
But if I use the following syntax the linter works, but the import obviously fails at run time.
import win32.lib.win32event
Any ideas on how I can "make" VSCode or the linter match the correct import?
Pylint has a configuration file, loaded by the command-line switch --rcfile. One of the entries in the configuration file is ignored-modules=. A comment line describes this option as a "list of module names for which member attributes should not be checked". There are several other options that are similar.
These options are needed because pylint is a static type checker, meaning that it doesn't load the module but merely inspects its source code. In the case of a module like the win32 collection, it uses .dll files that pylint cannot inspect. Therefore there is no way that pylint can figure out what names are exposed by win32. So the best you can do is tell pylint to suppress error messages.

Visual Studio Code - removing pylint

Simple question - but any steps on how to remove pylint from a Windows 10 machine with Python 3.5.2 installed.
I got an old version of pylint installed that's spellchecking on old Python 2 semantics and it's bugging the heck out of me when the squigglies show up in Visual Studio Code.
Open the workspace settings file (select File > Preferences > Settings, then locate Python configuration) and edit this line like this:
"python.linting.pylintEnabled": false
then save the file.
If you just want to disable pylint then the updated VSCode makes it much more easier.
Just hit CTRL + SHIFT + P > Select linter > Disabled Linter.
Hope this helps future readers.
The question was how to remove python linter, not how to disable it.
In order to remove pylint open Powershell/cmd and type:
pip uninstall pylint
If you still see the problem like "Missing class docstring Pylint(missing-class-docstring" after you tried the ways suggested in this page, it may because your VS Code installed the extension Pylint, you can hit CTRL + SHIFT + X to open your installed extension list, and disable it.
i had this problem but it was fixed with this solution CTRL + SHIFT + P > Selecionar linter > Linter desabilitado.
I have followed all instructions here, but even though pylint was disabled in the settings and in settings.json, window reloaded and everything, it still showed pylint errors instead of flake8, which I had selected and configured. It turned out I had an extension installed called "Linter" created by Nando Vieira which somehow started to overwrite the linting behaviour of Microsoft's "Python" extension. Disabling the "Linter" extension and reloading the window finally solved the problem.

Setting up eclipse for maya 2013

I followed this instructions:
http://www.luma-pictures.com/tools/pymel/docs/1.0/eclipse.html
Also have read the Maya's documentation:
http://download.autodesk.com/global/docs/maya2013/en_us/files/Python_Python_from_an_external_interpreter.htm#
And now I can successfully import and initialize Maya Standalone and
Cmds module.
BUT, as I try to code something like 'cmds.polyCube()', first I don't have any
auto completion and secondly Eclipse returns with an error saying that cmds module
Doesn't has any variable that named polyCube() etc....
Here is my exact procedure which I use to import and initialize maya inside Eclipse:
import maya.standalone
maya.standalone.initialize()
import maya
from maya import cmds
cmds.polyCube(n='cuby_01')
cmds.select('cuby_01')
Are you sure you followed this step from the pymel eclipse docs:
Click the “New Folder” button again, and add the site-packages directory you removed earlier. We did this in order to ensure that the
stub maya package is found before the real maya package. When you’re
done, the main site-packages directory should be somewhere below the
extras/completion/py folder you just added.
That is the important part for adding the stubs to your custom interpreter. In the end you should have a mayapy interpreter set up, with this added site-packages location. And also, make sure when you create a new pydev project, that you go into its specific properties and set the python interpreter to the mayapy that you set up. Otherwise you could still possibly be using the default python interp.
I wrote a little explanation here, how to add a mayapay interpreter here:
Eclipse environment for Maya's python modules
I'm pretty sure is this one your problem.
give a look and if you have any question don't hesitate to ask here again :)
You can also take a look at this tutorial:
http://www.creativecrash.com/tutorials/using-eclipse-as-a-maya-ide (the most relevant portion is available on the 'page 2' tab in the linked page). Basically, you need to point Eclipse's 'predefined' at the /devkit/other/pymel/extras/completion/pypredef
Your sample should work correctly as long as (a) you're using a 2.6 interpreter and (b) you've got the maya python directory in your eclipse PYTHONPATH:
Its usually easiest to configure eclipse to use /bin/mayapy.exe as the intepreter for maya. You might find it easier to use
import maya.standalone
maya.standalone.initialize()
import maya.cmds as cmds
pc = cmds.polyCube()
the cmds module imports as empty UNLESS you've already initialized maya.standalone - your sample shows that but perhaps you got that error in an earlier run without standalone.initialize()?

Categories