Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to get real time error in Visual code during python development

I am using Visual code for python development but somehow I am not able to show compile time error during python development.

I will get those errors only after run.

I have uninstalled visual code 3 times but still not able to solve it.

Visual code Image

Visual code Image_1

like image 584
Moon Avatar asked Jun 23 '19 04:06

Moon


People also ask

How do I get VS Code to show errors?

Right-click on the corresponding entry line and select Show Error Help from the context menu, or click on the hyperlinked error code value in the Code column of the Error List.

How does Visual Studio Code fix import error in Python?

To solve unresolved import error in Python, set your Python path in your workspace settings. If you are working with Visual Studio Code and import any library, you will face this error: “unresolved import”. Then reload the VSCode, and it will fix that error.


1 Answers

There's a few things that need to be in place before VS Code can give you the live feedback you're after.

  • You'll need to have Python installed on your system.
  • You'll need to have a Python language extension loaded - probably ms-python.python but there seem to be some alternatives available. Ctrl+Shift+X will get you to the extensions panel where you can search for Python and check that you've got something installed.
  • The file you're looking at needs to be recognised as a Python file. You can check this on the status bar in the bottom-right - you should see two icons on the far right, then a word describing the format of the file. If you hover over the word, the tooltip will say Select language mode. If this doesn't already say "Python", click on it and change it to Python. If you can't find Python, this probably indicates you don't have a Python language extension installed.
  • Code will need to have found a Python interpreter it can use. This is indicated on the bottom left side of the status bar - the first block of text should say something like "Python 3.7.3 32-Bit". If it says something else, try clicking it and choosing a pyhon interpreter.
  • The python environment run with that interpreter needs to have pylint installed. For me, when I selected the Python 3.7.3 32 Bit interpreter, Code popped up a warning about pylint not being installed. Clicking the button to install it didn't work; but I was able to slightly tweak the commandline it tried to C:/Users/jamez/AppData/Local/Programs/Python/Python37-32/python.exe -m pip install -U pylint --user.

Once I did that, Code is able to give me live feedback - I get red squigglies under "from xyz" and hovering over it lets me know that the problem is "Unable to import xyz"

like image 114
James Polley Avatar answered Sep 21 '22 05:09

James Polley