E0401:Unable to import 'flask'

前端 未结 6 1796
终归单人心
终归单人心 2021-02-07 08:53

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

相关标签:
6条回答
  • 2021-02-07 09:34

    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.

    0 讨论(0)
  • 2021-02-07 09:36

    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~

    0 讨论(0)
  • 2021-02-07 09:44

    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.

    0 讨论(0)
  • 2021-02-07 09:47

    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 .

    0 讨论(0)
  • 2021-02-07 09:51

    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 ;-)

    0 讨论(0)
  • 2021-02-07 09:58

    Go to Command Palette using Ctrl + Shift + P. select python:select interpreter and then choose your appropriate virtualenv.

    0 讨论(0)
提交回复
热议问题