I am using visual studio code to code in python. I have the Microsoft python extension. I am having trouble with basic bug detection. For example, I import a class that does not exist from a file because of a typo and that does not get detected at all. For example:
from my_functions import MFunction
while the name of the class is actually MyFunction
(y is missing in the call)
does not give signal an error in the UI at all and only throws an error at the run.
Is there another extension I need to install or some sort of config I haven't configured correctly?
CodePudding user response:
Have you tried using Linting Python? Here is a link for the same, hope it is what you are looking for.
CodePudding user response:
In visual studio code you have to consider your current working directory (CWD) plus the files and methods you want to import.
For example: If you open vscode in the folder of your project and open a terminal or start the python file with the ui "play" button, vscode might not set your cwd in the right folder for the "import"-command to find the package/function. The "import" command checks for your current PATH and if your folder is not in there it might not find the .py file and its containing functions to import it as a package (by the way yes the imported function needs to be imported exactly as it is defined in the .py file . Check the execution path in the terminal and if it is not set to project folder you have to "change directory" (cd) into your project folder. This will cause your python execution to run from your project folder and therefor find the .py file with its functions.
Another option would be to copying your .py file you want to import into the side-packages folder of your python installation.