Pylint "Unable to Import" Error - How to Set Pythonpath

VS Code pylint(import-error) Unable to import subsub-module from custom directory

I found a great workaround for my problem with this answer.
It points towards the message control part of the pylint-docs.

Practically, I just had to add the comment # pylint: disable=import-error behind my custom imports like so:

import General.Plotting.auxiliary_plotting_functions as aux_plot  # pylint: disable=import-error

This solves my issue perfectly, as I honestly didn't find an easy solution to this problem via configuring e.g. a .pylintrc file, let alone all my attempts with no avail involving PYTHONPATH and environment-files etc.

Put simply, my custom modules get imported correctly when executing the scripts in VS Code, but the only annoying detail was that pylint didn't get it and showed me useless import-errors. Now, pylint doesn't show this non-sense anymore, that's all I wanted :)

I'm sure there might be a more elegant solution, but so far the aforementioned workaround came in handy. If anyone comes up with a "better" solution, just post it here and I'll change the answer to yours.


PS for those using pylance as alternative linter in VS-Code:

A similar workaround (to the above-mentioned regarding pylint) I found here works fine (appending # type: ignore to the import-statement), which I mentioned in this question as well:

import General.Misc.general_tools as tools  # type: ignore

Most likely it's got something to do with the settings.json - file of VS-Code, since using VS-Code is the constant factor here.

Visual Studio Code pylint: Unable to import 'protorpc'

Open the settings file of your Visual Studio Code (settings.json) and add the library path to the "python.autoComplete.extraPaths" list.

"python.autoComplete.extraPaths": [
"~/google-cloud-sdk/platform/google_appengine/lib/webapp2-2.5.2",
"~/google-cloud-sdk/platform/google_appengine",
"~/google-cloud-sdk/lib",
"~/google-cloud-sdk/platform/google_appengine/lib/endpoints-1.0",
"~/google-cloud-sdk/platform/google_appengine/lib/protorpc-1.0"
],


Related Topics



Leave a reply



Submit