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):
- Open the workspace settings (settings.json)
- Identify the fully qualified path to the python executable (this could even be a virtual environment)
- Ensure Pylint is installed for the above python environment
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):
- Open the terminal window
- Activate the relevant python virtual environment
Ensure Pylint is installed within this virtual environment
pip install pylint
- Close all instances of VS Code
- 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:
Then press the green button on the upper right corner, run the file in Terminal.
The module py
usage is:
So the right command is py test.py -3
, also it's recommended that use the command python
to run .py file.
Related Topics
How to Click on an Element from the Dropdown Menu Through Python and Selenium
Python Replace Single Quotes Except Apostrophes
How to Export a Table Dataframe in Pyspark to Csv
Beautifulsoup Findall() Given Multiple Classes
Pandas To_Csv: Suppress Scientific Notation in CSV File When Writing Pandas to Csv
How to Get a Fields Particular Value of Json in Python
How to Test If a Column Exists and Is Not Null in a Dataframe
How to Convert Float into Hours Minutes Seconds
How to Pad a String With Leading Zeros in Python 3
Python - How to Separate Paragraphs from Text
What Is the Correct Way to Make My Pyqt Application Quit When Killed from the Console (Ctrl-C)
Pandas: Update Column Values from Another Column If Criteria
How to Append Two Bytes in Python
Django - How to Retrieve Data in Database in Dropdownlist
How to Remove Grid Lines on Image in Python