简体   繁体   English

VS 代码,Python ext,autopep8 未格式化

[英]VS Code, Python ext, autopep8 not formatting

When editing in VS Code, "Format Document" doesn't work.在 VS Code 中编辑时,“格式化文档”不起作用。 I get an error message:我收到一条错误消息:

Extension 'Python Language Basics' cannot format 'HelloWorld.py'扩展“Python 语言基础”无法格式化“HelloWorld.py”

  • Windows 10 OS version: Windows_NT x64 10.0.17134 Windows 10 操作系统版本:Windows_NT x64 10.0.17134
  • VS Code version: Code 1.39.2 (6ab5985, 2019-10-15T15:35:18.241Z) VS Code 版本:Code 1.39.2 (6ab5985, 2019-10-15T15:35:18.241Z)
  • Python extension is installed, version: 2019.10.44104 Python 扩展安装,版本:2019.10.44104
  • Paths to Python and Python scripts directory, are correct. Python 和 Python 脚本目录的路径是正确的。

I've checked the docs and settings for formatting and autopep8 is specified.我已经检查了格式化的文档和设置,并指定了 autopep8。 pip works and I've installed autopep8, but it isn't clear to me that this is necessary. pip 工作,我已经安装了 autopep8,但我不清楚这是必要的。 In any case, it doesn't work.无论如何,它不起作用。 I have de-installed/re-installed Visual Studio Code twice, no effect on the problem我已经卸载/重新安装了 Visual Studio Code 两次,对问题没有影响

import sys, os


print('Hello, World.')


print('This is cool...')

print()

Modules should be placed on two lines, extra lines removed.模块应该放在两行上,多余的行被移除。

I fixed it.我修好了它。

De-install Code卸载代码

De-install Python卸载 Python

Install Code安装代码

Install extension安装扩展

Install Python, don't take quick install, go through custom for all users, and that PATH is updated.安装Python,不要快速安装,go通过自定义为所有用户,并且PATH已更新。

'pip install autopep8' and check the scripts folder, that autopep8 is there and the PATH to the scripts folder is right. 'pip install autopep8' 并检查脚本文件夹,autopep8 在那里并且脚本文件夹的路径是正确的。 Try "autopep8" at a command line to see that it finds it.在命令行中尝试“autopep8”以查看它是否找到它。

Add Python interpreter in Code.在代码中添加 Python 解释器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM