pythonvisual-studio-codeformat

Correct virtual environment setup to allow VS Code to format Python Files (using autopep8, Black Formatter or Ruff)


In Visual Studio Code, all formatter extensions for Python are failing to format my .py files. Message is "Skipping standard library file".

I understand that formatters built into Python are no longer supported and I have installed separate formatter extensions autopep8, Black Formatter, Ruff

I also understand that the formatter will not work if the Python interpreter cannot be determined. I had uninstalled and re-installed Python in a different location and the Python version wasn't showing in the status bar. I have now selected the Python interpreter location and the version is correctly showing in the VS Code status bar. See this question

I also understand that there is an issue where project files are saved within the virtual environment. However, I believe I've correctly separated my project code from my virtual environment (env and project code are in peer folders) (See below and this question)

Currently I have

Using the context menu for the file and selecting "Format Document with" then each formatter in turn, I've then viewed the Output for that formatter. All report "Skipping standard library file", so this must be a VS Code issue, or a misunderstanding on my part with setting up the Virtual Environment, however I have separate folders for

I'm less than a week into learning Python/Django, so maybe I've missed something basic along the way in relation to virtual environment setup that's causing VS Code to believe my project file is a standard library file?


Solution

  • This is not ideal, but if all else fails try the "nuclear" option: Uninstall and reinstall Python, Visual Studio Code with required extensions. Delete and recreate the virtual environment and reinstall any project dependencies. Ensure project files are not located in the Python installation folder or the virtual environment.