E0401:Unable to import 'flask'
Solution 1
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 .
Solution 2
Go to Command Palette using Ctrl + Shift + P
.
select python:select interpreter
and then choose your appropriate virtualenv.
Solution 3
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.
Solution 4
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 ;-)
Solution 5
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.
Admin
Updated on January 09, 2022Comments
-
Admin over 2 years
Am new in flask development and trying to import flask in my project but
Pylint
is giving this error in VSCodeE0401:Unable to import 'flask'
, but I installed flask already in my project but I don't know how to solve this, how can I resolve it.My virtual environment is installed , and the image which proves is below:
The error am getting code , the underlined from:
what am I missing?
-
Admin almost 6 yearsI edited my post , that's what I see as my virtual env
-
suspicious_williams over 4 yearsThis worked for me. I was following the gcp Flask tutorial and received the same error. On my system (macOS) I had to type
>Python:
to display a list of python commands, then selectSet Interpreter
-
montrealist almost 4 yearsAlso need to restart the VS Code terminal to pick that up!
-
montrealist almost 4 yearsAlso need to restart the VS Code terminal to pick that up!
-
Noumenon over 3 yearsTo expand on "Select virtual environment that you created": I had to browse to
venv/Scripts/python.exe
(on Windows).