vscode 配置python 开发环境

1、 安装  Python extension for VS Code

2、点击选择python解释器, ==> Enter interpreter path ==> Find ... , 找到python解析器的路径 ,

 在settings.json中会添加 python.pythonPath字段:

 注意:如果未打开工作空间文件夹时 选择解释器,则VS Code会在用户设置中设置python.pythonPath,这通常设置VS Code的默认解释器。 用户设置可确保您始终具有用于Python项目的默认解释器。 通过工作区设置,您可以覆盖用户设置。

查看用户设置和工作区设置 ,点击File > Preferences > Settings

点击右上角的图标可以切换到json文件格式

3、使用linters (用来提示错误)

open the Command Palette (Ctrl+Shift+P) and select the Python: Select Linter command

This command adds "python.linting.<linter>Enabled": true to your settings, where <linter> is the name of the chosen linter。 我选择的是flake8, 在settings.json中会自动生成如下配置:

 启用linter会提示您在所选环境中为所选linter安装所需的软件包。 需要通过pip install flake8 安装所需的软件包

 

4、安装 yapf

① pip install yapf

② 在settings.json中添加     "python.formatting.provider": "yapf"

可以用来格式化代码,  右键 --> Format Document , 让代码符合PEP-8 规范。

最后的 settings.json配置文件如下:

{
    "python.pythonPath": "c:\\ml\\ml\\Scripts\\python.exe",
    "python.linting.pylintEnabled": false,
    "python.linting.flake8Enabled": true,
    "python.linting.enabled": true,
    "python.linting.flake8Args": [
        "--max-line-length=248"
    ],  // 设置每行代码的最大长度为248
    "python.formatting.provider": "yapf"
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值