Am new in flask development and trying to import flask in my project but Pylint
is giving this error in VSCode E0401:Unable to import \'flask
I guess VS Code doesn't use the correct virtualenv.
To select a virtualenv using the GUI, see Configuring Python environments.
If you use the terminal and have code
in your path, launch VS code from your workspace and the virtualenv will be loaded automatically:
cd python-workspace
code -n python-workspace
(note: the -n
is for new window)
If this does not work, ensure that pylint
is installed in your virtualenv (i.e. your are not using the global pylint
). If it still does not work, have a look at this troubleshooting guide.
In my case, the vscode cannot run the lint becouse my flask install with venv environment, so I deactivate the vent and install flask again in the normal environment , the lint will be work~
I have the same problem when I code in VS code.
I open Command Palette by ⇧⌘P. And run the linter to solve this problem like this picture.
Here is the document from VS code.
Solution is to switch Interpreter
Simple solution :
Go to command palette Type-- Python:Select Interpreter
Select virtual environment that you created
answered specifically for vscode can work for other also .
Due to the fact that you are using a virtual environment, first of all it's required that Pylint is installed inside this virtual env.
Furthermore, you need to add the following entry to your workspace settings to avoid the [pylint] E0401
error:
"python.linting.pylintPath": "/path/to/your/virtualenv/bin/pylint"
This overrides the user settings (global settings) and instructs VSCode to use the Pylint version within your virtual env (instead of the global one). That was probably the point you was missing ;-)
Go to Command Palette using Ctrl + Shift + P
.
select python:select interpreter
and then choose your appropriate virtualenv.