Visual Studio Code Pylint: Unable to Import 'Protorpc'

Visual Studio Code pylint: Unable to import 'protorpc'

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.

VS CODE: Unable to import - pylint(import:error)

If your project is running normally with views,the problem is with the extension,not with your code.disable them and try again.

'Unable to import' errors for anaconda environment in VS Code

According to the Python in Visual Studio Code docs, this is probably due to Visual Studio Code pointing at the wrong Python version.

1. Unable to import (pylint)


  • Scenario: You have a module installed, however the linter in the IDE is complaining about; not being able to import the module, hence error
    messages such as the following are displayed as linter errors:

    .. unable to import 'xxx' ..
  • Cause: The Python extension is most likely using the wrong version of Pylint.

Solution 1: (configure workspace settings to point to fully qualified python executable):

  1. Open the workspace settings (settings.json)
  2. Identify the fully qualified path to the python executable (this could even be a virtual environment)
  3. Ensure Pylint is installed for the above python environment
  4. Configure the setting "pythonPath" to point to (previously identified) the fully qualified python executable.

    "python.pythonPath": "/users/xxx/bin/python" ```

Solution 2: (open VS Code from an activated virtual environment):

  1. Open the terminal window
  2. Activate the relevant python virtual environment
  3. Ensure Pylint is installed within this virtual environment

    pip install pylint
  4. Close all instances of VS Code
  5. Launch VS Code from within this terminal window

    (this will ensure the VS Code process will inherit all of the Virtual Env environment settings)

Trying to import numpy but VSCode gives me pylint(import-error)?

After installing numpy, use pip show numpy to check if it was installed in current environment:

Sample Image

Then press the green button on the upper right corner, run the file in Terminal.

The module py usage is:

Sample Image

So the right command is py test.py -3, also it's recommended that use the command python to run .py file.

Sample Image



Related Topics



Leave a reply



Submit