20

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?

nde
  • 327
  • 1
  • 2
  • 6

7 Answers7

10

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.

Brett Cannon
  • 14,438
  • 3
  • 45
  • 40
  • 3
    Yes, that was exactly the problem. First I needed to install autopep8 into my virtual environment. Then I had to select that venv rather than use the default venv which didn't contain that package. I wasn't aware of the formatOnSave setting so thanks for pointing that out. – nde May 21 '20 at 22:46
5

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
Jiao
  • 111
  • 1
  • 3
4

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.
Chen Wang
  • 448
  • 2
  • 11
  • That is a good answer. The only thing missing is the way to **find** the Autopep8 path. In Windows, you can use [@Vaibhav Gupta 's answer](https://stackoverflow.com/questions/64326326/how-can-i-change-the-path-in-vs-code-to-the-extension-and-what-is-the-correct-pa#answer-66900140) : In the command line type `where.exe autopep8` and copy that path to the Autopep8 Path – Leonardo Pinheiro Feb 12 '22 at 01:19
3
pip install pep8   
pip install --upgrade autopep8

or

"python.formatting.provider": "autopep8"
wazowski
  • 115
  • 8
1

Adding this in for anyone who has this issue running WSL on Windows. You need to either need to be connected to Remote WSL in order to access pep8 in your WSL Python installation or install Python and pep8 on Windows since VS Code will be looking on Windows. No matter how magnificently installed autopep8 may be in WSL, VS Code won't find it.

So my full solution was:

  1. If you don't have Python installed in Windows, do that (dare I suggest you can even get it in the Microsoft Store!)
  2. Install autopep8 in your Windows Python instance. e.g., from Command Prompt:
    python3 -m pip install autopep8
    
  3. Follow the instructions in any of the other responses if you're still having issues.
Carter M
  • 11
  • 1
1

The easiest way to work with autopep8 in VSCode to follow the steps:

  1. install autopep8 via pip install autopep8 into the desired virtual env
  2. Open VSCode and press ctrl + , which will open the settings
  3. Search for formatter
  4. Select Python-autopep8 in Editor: Default Formatter
  5. One can also tick the Editor: Format On Save if he/she wishes to
  6. Most importantly, open any .py file in that directory via VSCode and check at the bottom right of the of the VSCode window. Make sure that it is showing the venv name where the autopep8 has been installed and configured. enter image description here
EMT
  • 458
  • 3
  • 14
0

Install autopep from your terminal by running the following command

    python -m pip install autopep8

That should solve the error 2 in vscode of no such file or directory error