vscode+python

1、设置python虚拟解释器:
设置快捷键:


image.png

或者点击.py文件的右下角:第一个是配置.py对应的语言,第二个配置语言的解释器


image.png

2、安装扩展:
image.png

image.png

image.png

其实就3个:
python
python extension pack
pylance
black

3、.env和setting.json配置:


image.png

.env

PYTHONPATH = F:/20240424/2022/code/python/source/ftachina/src

setting.json

{ //对第三方库(比如pip)和用户自己的文件进行index
    //index后,将会ctrl+c后,自动提示
    //若为false,则不index,则必须import 
    //自己代码如果手动打开,会触发index,则ctrl+c会提示。
    "python.analysis.indexing": true,
    //是否自动搜索python.analysis.extraPaths配置下的src文件(workspace下的src会自动搜索,不需要配置成true)
    // "python.analysis.autoSearchPaths": true,
    //index后,敲入字符,是否自动提示补全代码.
    //自己的代码的包名和模块名以及非__all__的函数,还需要import一次(或者打开__init__文件),才能生效。
    "python.analysis.autoImportCompletions": true,
    // "python.envFile": "${workspaceFolder}/.vscode/.env",
    // "python.languageServer": "Default",
    //打开languageServer的日志
    "python.analysis.logLevel": "Trace",
    //对第三方库的代码搜索的深度
    //自己的代码不起作用11
    "python.analysis.packageIndexDepths": [
        {
            "name": "",
            "depth": 10,
            "includeAllSymbols": true
        },
    ],
    //是否包含小括号;系统自动生成的函数调用方法
    "python.analysis.completeFunctionParens": true,
    "python.linting.pylintEnabled": false,
    "python.linting.enabled": true,
    "python.envFile": "${workspaceFolder}/.vscode/.env",
    "python.analysis.extraPaths": [
        // "./src/rfc"
    ],
    // "[python]": {
    //     "editor.defaultFormatter": "giyyapan.pyformat",
    //     "editor.codeActionsOnSave": {
    //         /** Pyformat use it's own code action to  */
    //         "source.organizeImports": true
    //     }
    //     // "editor.formatOnSaveMode": "modificationsIfAvailable",
    // },
    "editor.formatOnPaste": true,
    "editor.formatOnSave": true,
    "editor.formatOnSaveMode": "modificationsIfAvailable",
    "editor.formatOnType": true,
    "files.autoSave": "afterDelay",
    // "editor.formatOnSave": true,
    // "python.analysis.importFormat": "absolute",
    // "python.analysis.fixAll": "source.convertImportFormat"
    /*   "python.analysis.extraPaths": [
        "F:/2022/code/python/source/fti/src/**"
    ], */
    /* "python.analysis.include": [
        "F:/2022/code/python/source/fti/src/**"
] */
}

5、运行配置:
launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
        },
        {
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "${workspaceFolder}/src/vscode.webapp.py",
                "FLASK_ENV": "development",
                "FLASK_DEBUG": "1",
            },
            "args": [
                "run",
                "--debugger",
                "--reload",
                "-p 9002",
                // "-host 0.0.0.0"
            ],
            "jinja": true,
            // "justMyCode": false
        }
    ]
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容