pythonvs配置

本文详细介绍了在VSCode中配置Python开发环境的方法,包括task.json、settings和launch配置的使用,以及如何设置Python解释器路径、linting工具、调试选项等,为Python开发者提供了实用的指南。

参考此篇博客https://blog.youkuaiyun.com/u013205877/article/details/78883405

task.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "args": [
                "${file}"
            ],
            "command": "/home/wujunjie/anaconda2/envs/py366/bin/python",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

setting:

{
    "python.pythonPath":"/home/wujunjie/anaconda2/envs/py366/bin/python",
    "python.linting.pylintPath":"/home/wujunjie/anaconda2/envs/py366/bin/pylint"

}

lauch:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File (Integrated Terminal)",
            "type": "python",
            "request": "launch",
            "stopOnEntry":true,
            "program": "${file}",
            "python.pythonPath":"/home/wujunjie/anaconda2/envs/py366/bin/python",
            "cwd":"${workspaceFolder}",
            "env":{},
            "envFile":"${workspaceFolder}/.env",
            "debugOptions":["RedirectOutput"]
            
        },
        {
            "name": "Python: Attach",
            "type": "python",
            "request": "attach",
            "port": 5678,
            "host": "localhost"
        },
        {
            "name": "Python: Module",
            "type": "python",
            "request": "launch",
            "module": "enter-your-module-name-here",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "console": "integratedTerminal",
            "args": [
                "runserver",
                "--noreload",
                "--nothreading"
            ],
            "django": true
        },
        {
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "app.py"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "jinja": true
        },
        {
            "name": "Python: Current File (External Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "externalTerminal"
        }
    ]
}

 

在Visual Studio Code中配置Python环境,可按以下步骤进行: 1. **安装Visual Studio Code**:这是配置环境的基础工具,需要先完成安装。 2. **安装Python**:为后续的Python开发提供运行环境。 3. **安装Python扩展**:扩展可以增强VS Code对Python的支持。 4. **配置Python解释器**:检查Python安装与PATH配置,需要起一个和VScode中配置的变量同名变量(如pythonPath),并在变量后面写上Python的地址,同时在Path中也配置python的地址。例如在配置文件中设置 “python.pythonPath”: “C:\Python39”,这个名字 “pythonPath” 需要在环境变量里也配置 [^1][^2][^3]。 5. **配置其他Python工具** - **安装和配置Linter**:如启用flake8,需要先使用 `pip3 install flake8` 进行安装,并在配置文件中设置 “python.linting.flake8Enabled”: true [^3]。 - **安装和配置Formatter**:例如启用yapf,先使用 `pip3 install yapf` 安装,在配置文件中设置 “python.formatting.provider”: “yapf” [^3]。 - **配置测试框架**:满足Python代码测试需求。 6. **调试配置**:方便对Python代码进行调试。 7. **编写和运行Python代码**:完成环境配置后,即可开始Python代码的开发工作 [^1]。 ### 示例配置文件内容 ```json { "git.ignoreLegacyWarning": true, "workbench.iconTheme": "vscode-icons", "python.pythonPath": "C:\\Python39", "editor.lineHeight": 26, "editor.fontSize": 18, "editor.wordWrap": "on", "editor.formatOnSave": true, "python.linting.flake8Enabled": true, "python.formatting.provider": "yapf", "editor.renderIndentGuides": false, "path - intellisense.autoSlashAfterDirectory": true, "path - intellisense.extensionOnImport": true, "workbench.colorTheme": "Monokai", "python.linting.pylintArgs": [ "--load - plugins", "pylint_django", "--disable - msg=C0111" ], "terminal.integrated.fontFamily": "monospace", "editor.fontWeight": "500", "python.defaultInterpreterPath": "C:\\Python39" } ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值