资讯专栏INFORMATION COLUMN

mac vscode Python配置

linkin / 369人阅读

摘要:在完成设置编辑之后,输入来保存更改,更改会立即生效。调试配置文件使用了解相关属性。欲了解更多信息,请访问任务配置直接运行配置

配置编辑器 1. 基础设置settings.json

VS Code有很多选项可以来配置编辑器,你可以通过用户设置来设置全局选项,或在工作空间设置中针对每个文件夹或项目设置,选项设置保存在settings.json 文件中。

Files > Preferences > User Settings (或者按下 kb(workbench.action.showCommands), 输入 user 然后按下 Enter) 来编辑 settings.json 文件.

Files > Preferences > Workspace Settings (或者按下 kb(workbench.action.showCommands), 输入 worksp 然后按下 Enter) 来编辑工作空间的 settings.json 文件.

你会看到VS Code 默认配置在左侧窗口并且你编辑的 settings.json 在右侧。你可以只是从默认设置查看和拷贝设置。

在完成设置编辑之后,输入 kb(workbench.action.files.save) 来保存更改,更改会立即生效。

settings.json

{
  "python.pythonPath": "/usr/local/opt/python3/bin/python3.6"
}
2. 调试配置文件launch.json

launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
    
        {
            "name": "Python",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "${config:python.pythonPath}",
            "program": "${file}",
            "cwd": "${workspaceRoot}",
            "env": {},
            "envFile": "${workspaceRoot}/.env",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ]
        },
        {
            "name": "Python: Attach",
            "type": "python",
            "request": "attach",
            "localRoot": "${workspaceRoot}",
            "remoteRoot": "${workspaceRoot}",
            "port": 3000,
            "secret": "my_secret",
            "host": "localhost"
        },
        {
            "name": "Python: Terminal (integrated)",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "${config:python.pythonPath}",
            "program": "${file}",
            "cwd": "",
            "console": "integratedTerminal",
            "env": {},
            "envFile": "${workspaceRoot}/.env",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit"
            ]
        },
        {
            "name": "Python: Terminal (external)",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "${config:python.pythonPath}",
            "program": "${file}",
            "cwd": "",
            "console": "externalTerminal",
            "env": {},
            "envFile": "${workspaceRoot}/.env",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit"
            ]
        },
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "${config:python.pythonPath}",
            "program": "${workspaceRoot}/manage.py",
            "cwd": "${workspaceRoot}",
            "args": [
                "runserver",
                "--noreload",
                "--nothreading"
            ],
            "env": {},
            "envFile": "${workspaceRoot}/.env",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput",
                "DjangoDebugging"
            ]
        },
        {
            "name": "Python: Flask (0.11.x or later)",
            "type": "python",
            "request": "launch",
            "stopOnEntry": false,
            "pythonPath": "${config:python.pythonPath}",
            "program": "fully qualified path fo "flask" executable. Generally located along with python interpreter",
            "cwd": "${workspaceRoot}",
            "env": {
                "FLASK_APP": "${workspaceRoot}/quickstart/app.py"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "envFile": "${workspaceRoot}/.env",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ]
        },
        {
            "name": "Python: Flask (0.10.x or earlier)",
            "type": "python",
            "request": "launch",
            "stopOnEntry": false,
            "pythonPath": "${config:python.pythonPath}",
            "program": "${workspaceRoot}/run.py",
            "cwd": "${workspaceRoot}",
            "args": [],
            "env": {},
            "envFile": "${workspaceRoot}/.env",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ]
        },
        {
            "name": "Python: PySpark",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "osx": {
                "pythonPath": "${env:SPARK_HOME}/bin/spark-submit"
            },
            "windows": {
                "pythonPath": "${env:SPARK_HOME}/bin/spark-submit.cmd"
            },
            "linux": {
                "pythonPath": "${env:SPARK_HOME}/bin/spark-submit"
            },
            "program": "${file}",
            "cwd": "${workspaceRoot}",
            "env": {},
            "envFile": "${workspaceRoot}/.env",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ]
        },
        {
            "name": "Python: Module",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "${config:python.pythonPath}",
            "module": "module.name",
            "cwd": "${workspaceRoot}",
            "env": {},
            "envFile": "${workspaceRoot}/.env",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ]
        },
        {
            "name": "Python: Pyramid",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "${config:python.pythonPath}",
            "cwd": "${workspaceRoot}",
            "env": {},
            "envFile": "${workspaceRoot}/.env",
            "args": [
                "${workspaceRoot}/development.ini"
            ],
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput",
                "Pyramid"
            ]
        },
        {
            "name": "Python: Watson",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "${config:python.pythonPath}",
            "program": "${workspaceRoot}/console.py",
            "cwd": "${workspaceRoot}",
            "args": [
                "dev",
                "runserver",
                "--noreload=True"
            ],
            "env": {},
            "envFile": "${workspaceRoot}/.env",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ]
        }
    ]
}
3. 任务配置(直接运行配置)tasks.json

tasks.json

{
    "version": "0.1.0",
    "command": "python3",
    "isShellCommand": true,
    "args": ["${file}"],
    "showOutput": "always"
}

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/41034.html

相关文章

  • koroFileHeader 非常实用的Vscode 插件[用于添加文件头部注释]

    摘要:使用文件头部注释在当前编辑文件中使用快捷键即可生成文件头部注释。事实上,函数注释在文件的任意位置都可生成,这里需要自己控制。 koroFileHeader 一个读取用户自定义模板,通过快捷键添加文件头部注释、在光标处添加函数注释的VsCode插件 language 简体中文 | English 一些文档 支持语言 插件设置/配置 更新日志 常见问题 简介 文件头部添加注释: 在文...

    hoohack 评论0 收藏0
  • VsCode 添加文件头部注释和函数注释[koroFileHeader]

    摘要:使用文件头部注释在当前编辑文件中使用快捷键即可生成文件头部注释。函数注释将光标放在函数行或者将光标放在函数上方的空白行使用快捷键,即可生成函数注释。事实上,函数注释在文件的任意位置都可生成,这里需要自己控制。 koroFileHeader 一个读取用户自定义模板,通过快捷键添加文件头部注释、在光标处添加函数注释的VsCode插件 language 简体中文 | English 更新日志...

    superPershing 评论0 收藏0
  • 【Electron】酷家乐客户端开发实践分享 — 浏览器启动客户端

    摘要:作者钟离,酷家乐客户端负责人原文地址酷家乐客户端下载地址文章背景在酷家乐客户端在改版成功后,我们积累了许多的宝贵的经验和最佳实践。钟离可以注册多个协议接收参数协议注册完毕之后,我们已经可以在浏览器中,通过访问自定义协议来启动客户端了。 作者:钟离,酷家乐PC客户端负责人原文地址:https://webfe.kujiale.com/browser-to-client/酷家乐客户端:下载...

    Cciradih 评论0 收藏0
  • 【Electron】酷家乐客户端开发实践分享 — 浏览器启动客户端

    摘要:作者钟离,酷家乐客户端负责人原文地址酷家乐客户端下载地址文章背景在酷家乐客户端在改版成功后,我们积累了许多的宝贵的经验和最佳实践。钟离可以注册多个协议接收参数协议注册完毕之后,我们已经可以在浏览器中,通过访问自定义协议来启动客户端了。 作者:钟离,酷家乐PC客户端负责人原文地址:https://webfe.kujiale.com/browser-to-client/酷家乐客户端:下载...

    刘德刚 评论0 收藏0
  • Python入门-环境搭建

    摘要:统一码,万国码编码此时应运而生,年由统一码联盟首次发布标准。英文占个字节欧洲语系占个东亚占个,其它及特殊字符占个使用个字节表示所有字符优先使用个字节,否则使用个字节表示。退出交互式环境,使用。 < 返回索引页 计算机编程基础知识 编程入门准备知识 计算机基本组成 计算机中的编码 一门语言的基本组成 环境搭建 Python下载和安装(window/mac/linux...

    xzavier 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<