How to use Flake8 in VSCode?
Asked Answered
D

5

36

My VSCode is using a locally installed anaconda environment, at the default directory, which places it in Program Files. Because of this I'm unable to install flake8 through VSCode, I get a permission error. If I update my conda environment at the local level to install flake8, does anyone know if VSCode recognize and be able to use the package then?

Disquieting answered 12/1, 2019 at 13:52 Comment(0)
B
35

Usually yeah it will. But if it doesn't work for you, then you can try specifying absolute path to flake8 and enable it explicitly like so :

"python.linting.flake8Enabled": true,  
"python.linting.flake8Path": "path/to/flake8",  

you can even specify path to your conda environment :

"python.condaPath": "path/to/condaenv/",
Bridgettbridgette answered 12/1, 2019 at 14:5 Comment(1)
This worked for me - in VS, you simply open Setting, search for flak8, find needed path, and insert in corresponding JSON file for flake8 configuration.Unimposing
P
19

Have you tried to:

  1. ctrl + shift + p
  2. write "select linter" then click on it
  3. click on flake8

Maybe that helps.

Phonics answered 19/4, 2021 at 3:15 Comment(1)
I installed Flake8 in the VS Code extension, but I don't see "select linter" via ctrl+shift+p.Gushy
P
4

Yes, it will. You'll have to install flake8 into each environment that you specify as an interpreter for a project in VSCode.

Pastypat answered 12/1, 2019 at 13:54 Comment(1)
Is there a way to bypass the permission error in VSCode to install from there? I just tried installing through anaconda navigator which worked fine but VSCode isn't recognizing it, either way you answered my question. Thank youDisquieting
S
2

I just installed Flake8 extension to VSCode as shown below. *I use Anaconda on Windows 11:

enter image description here

Then, it works properly as shown below:

enter image description here

Superorganic answered 9/6, 2023 at 23:56 Comment(0)
E
0

VSCode changed the linting settings. The recommended way to do it now is using an extension. So install Flake8 extension.

Newer versions of the extension has an Flake8 linter embedded. So you don't need to install it in your machine.

VSCode documentation about linting improved a lot. Take a look, but is a summary:

  1. Install Flake8 extension
  2. It just works.

BTW: you should create a separated virtual environment for each of your projects. Doing this you'll be able to locally install packages.

Explain answered 29/5 at 16:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.