Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop autopep8 not installed messages in Code

I'm a new Python programmer using the Mac version of VS Code 1.45.1 to create a Django project. I have the Python and Django extensions installed. Every time I save a Django file, Code pops up this window:

Formatter autopep8 is not installed.  Install?
Source: Python (Extension)  [Yes] [Use black] [Use yapf]

I keep clicking the "Yes" button to install the autopep8 extension but this message keeps popping up nevertheless. Is there some trick to configuring VS Code so that this extension will be installed permanently and I stop getting this error?

like image 703
nde Avatar asked May 20 '20 21:05

nde


People also ask

How do I use autopep8 commands?

If you're using eclipse + PyDev you can simply activate autopep8 from PyDev's settings: Windows -> Preferences -> type 'autopep8' in the search filter. Show activity on this post. There are many. IDEs usually have some formatting capability built in.

What is Python autopep8?

autopep8 automatically formats Python code to conform to the PEP 8 style guide. It uses the pycodestyle utility to determine what parts of the code needs to be formatted. autopep8 is capable of fixing most of the formatting issues that can be reported by pycodestyle.


4 Answers

You will receive this prompt if

  1. You have "formatOnSave" turned on as a setting
  2. You selected autopep8 as your formatter
  3. The Python extension can't find autopep8

So the options are:

  1. Turn off formatting on save
  2. Make sure you successfully installed autopep8 into your environment or you specified the path to autopep8 in your settings

My guess is there's an installation failure because you are using a globally installed interpreter and you're not allowed to install where pip wants to put autopep8.

like image 138
Brett Cannon Avatar answered Oct 17 '22 10:10

Brett Cannon


I have also encountered this problem in my computer with Ubuntu 18.04. It turns out that the python extension need some settings. My solution is:

  1. Go to Python extension's extension setting.
  2. Find Python>Formatting:Autopep8 Path term
  3. Add the full path of the autopep8 that you have installed.
like image 44
Chen Wang Avatar answered Oct 17 '22 10:10

Chen Wang


pip install pep8   
pip install --upgrade autopep8

or

"python.formatting.provider": "autopep8"
like image 3
fella7ena Avatar answered Oct 17 '22 12:10

fella7ena


windows 10: on vscode terminal:

  1. pip install autopep8
  2. where autopep8 enter image description here
  3. vscode -> Settings -> python -> Autopep8 Path: paste step2 enter image description here
like image 2
Jiao Avatar answered Oct 17 '22 10:10

Jiao