4

I use Visual Studio Code for developing in Django. I did all of the following inside a virtual environment.

Whenever I save the Python (.py) files, an alert pops up at the bottom right of the screen telling me: "Formatter autopep8 is not installed. Install?". It gives me three options - "Yes", "Use black, and "Use yapf".

If I click "Yes", it gives me another alert saying that there is no pip installer available in the selected environment. I then tried to go inside the integrated terminal and run pip install autopep8 and it says in the terminal that it was installed successfully. But when I save the Python files, it still gives me the same alert. Check the photo below.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Safwan Samsudeen
  • 1,645
  • 1
  • 10
  • 25
  • Check this: `python3 -m venv --upgrade ENV_DIR` as here described: https://stackoverflow.com/questions/10218946/upgrade-python-in-a-virtualenv – SdSaati Jan 21 '22 at 04:53

1 Answers1

2

Open your command palette with Shift + + P. Type in Preferences: Open Workspace Settings. I'll share the settings I use with you, some of which may be of interest:

{
    "python.pythonPath": "${workspaceFolder}/backend/env/bin/python3",
    "python.venvPath": "${workspaceFolder}/backend/env",
    "python.linting.flake8Enabled": true,
    "python.linting.flake8Path": "flake8",
    "python.linting.flake8Args": ["--ignore", "E501"],
    "python.linting.pylintEnabled": true,
    "python.linting.pylintPath": "pylint",
    "python.linting.pylintArgs": ["--load-plugins", "pylint_django"]
}
  • python.pythonPath is the location of the Python interpreter executable within your virtual environment. In this case it's an environment named env in a folder named backend. *${workspaceFolder} is a reference to where your project lives.
  • python.venvPath is the folder of your virtual environment(s).
  • The remaining six key/values are for enabling and execution for flake8 and pylint. Experiment with either.

Note that these are the workspace settings and not the user settings. User settings are applied across all of your Visual Studio Code projects.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Micah Danger
  • 104
  • 4
  • Thanks, but I solved the problem by selecting the Python 3.8.5 64 bit interpreter. By default, it was Python 2.7.16 64 bit interpreter. – Safwan Samsudeen Aug 22 '20 at 01:03