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
- VS Code v1.85
- Python v3.12.1
- autopep8 v2023.8.0
- Black Formatter 2023.6.0
- Ruff 2024.0.0
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
- Python (hovering over the Python version in the VS code status bar shows correct location)
- Python Dev Env
- Python Django Projects (completely separate form the virtual environment)
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?
2
Answers
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.
You can add the following codes to your
settings.json
:You can also right-click in your script and choose Format Document With… to set the formatter.