python and VScode

 

 mac 下vscode配置python

 

  • command + shift + P 输入task

 

 

  • 打开第一个配置文件tasks.json



    •  {   "version": "0.1.0",
          "command": "python",
          "isShellCommand": true,
          "args": ["${file}"],
          "showOutput": "always"
      }
       
    • 新建一个test.py
    • command + shift + B运行py文件


    •  
      •  配置python debug
      • 1、新建一个python项目
      • 2、打开launch.json文件
  •  3、修改lanuch.json文件为:
  • {
        "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": "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": "Integrated Terminal/Console",
                "type": "python",
                "request": "launch",
                "stopOnEntry": true,
                "pythonPath": "${config:python.pythonPath}",
                "program": "${file}",
                "cwd": "",
                "console": "integratedTerminal",
                "env": {},
                "envFile": "${workspaceRoot}/.env",
                "debugOptions": [
                    "WaitOnAbnormalExit",
                    "WaitOnNormalExit"
                ]
            },
            {
                "name": "External Terminal/Console",
                "type": "python",
                "request": "launch",
                "stopOnEntry": true,
                "pythonPath": "${config:python.pythonPath}",
                "program": "${file}",
                "cwd": "",
                "console": "externalTerminal",
                "env": {},
                "envFile": "${workspaceRoot}/.env",
                "debugOptions": [
                    "WaitOnAbnormalExit",
                    "WaitOnNormalExit"
                ]
            },
            {
                "name": "Django",
                "type": "python",
                "request": "launch",
                "stopOnEntry": true,
                "pythonPath": "${config:python.pythonPath}",
                "program": "${workspaceRoot}/manage.py",
                "cwd": "${workspaceRoot}",
                "args": [
                    "runserver",
                    "--noreload"
                ],
                "env": {},
                "envFile": "${workspaceRoot}/.env",
                "debugOptions": [
                    "WaitOnAbnormalExit",
                    "WaitOnNormalExit",
                    "RedirectOutput",
                    "DjangoDebugging"
                ]
            },
            {
                "name": "Flask",
                "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": "Flask (old)",
                "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": "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": "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"
                ]
            },
            {
                "name": "Attach (Remote Debug)",
                "type": "python",
                "request": "attach",
                "localRoot": "${workspaceRoot}",
                "remoteRoot": "${workspaceRoot}",
                "port": 3000,
                "secret": "my_secret",
                "host": "localhost"
            }
        ]
    }
  • 4、debug窗口就会出现python debug 字样,就可以直接debug了;


  •  完毕!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WSL (Windows Subsystem for Linux) allows you to run a Linux environment on your Windows machine. Using WSL with Visual Studio Code is a popular choice for Python development. Here are the steps to set up WSL, install Visual Studio Code, and use it for Python development: 1. Install WSL: Open PowerShell as an administrator and run the following command to enable WSL: ``` dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart ``` Then, restart your computer. 2. Install a Linux distribution: Open the Microsoft Store and search for a Linux distribution like Ubuntu. Install it and launch it to complete the setup. 3. Install Visual Studio Code: Download and install Visual Studio Code from the official website for Windows. 4. Open Visual Studio Code in WSL: Launch WSL (e.g., Ubuntu) from the Start menu and install Python inside WSL using the package manager (`apt-get` or `apt`). Open Visual Studio Code by typing `code` in the WSL terminal. 5. Install the Python extension: Inside Visual Studio Code, click on the Extensions icon on the left sidebar, search for "Python", and install the official Python extension from Microsoft. 6. Configure Python interpreter: Click on the Python version in the bottom-left corner of Visual Studio Code and select "Python: Select Interpreter". Choose the Python interpreter installed in your WSL distribution. 7. Start coding: You are now ready to write and execute Python code using Visual Studio Code in WSL. You can create a new Python file or open an existing one, and then use features like IntelliSense, debugging, and terminal directly within Visual Studio Code. Remember to set up any additional dependencies or libraries you may need for your Python projects within the WSL environment. I hope this helps you get started with using WSL, Visual Studio Code, and Python together! Let me know if you have any further questions.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值