溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

VSCode下如何配置python調(diào)試運(yùn)行環(huán)境

發(fā)布時(shí)間:2021-02-22 11:35:55 來源:億速云 閱讀:368 作者:清風(fēng) 欄目:開發(fā)技術(shù)

這篇“VSCode下如何配置python調(diào)試運(yùn)行環(huán)境”文章,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要參考一下,對(duì)于“VSCode下如何配置python調(diào)試運(yùn)行環(huán)境”,小編整理了以下知識(shí)點(diǎn),請(qǐng)大家跟著小編的步伐一步一步的慢慢理解,接下來就讓我們進(jìn)入主題吧。

vscode有什么用

Visual Studio Code 是一個(gè)運(yùn)行于 OS X,Windows和 Linux 之上的,針對(duì)于編寫現(xiàn)代 web 和云應(yīng)用的跨平臺(tái)編輯器,它為開發(fā)者們提供了對(duì)多種編程語言的內(nèi)置支持,并且正如 Microsoft 在Build 大會(huì)的 keynote 中所指出的,這款編輯器也會(huì)為這些語言都提供了豐富的代碼補(bǔ)全和導(dǎo)航功能。

VSCode配置python調(diào)試環(huán)境

很久之前的一個(gè)東東,翻出來看看

  • VSCode配置python調(diào)試環(huán)境
     * 1.下載python解釋器
     * 2.在VSCode市場中安裝Python插件
     * 4.在用戶設(shè)置里加兩條
     * 5.接下來是正式的調(diào)試了

    • Input

    • Output

    • Input示例

    • Output示例

    • 1080 兩個(gè)數(shù)的平方和

1.下載python解釋器

python 3.6.3 for windows

安裝到系統(tǒng)某個(gè)路徑例如C:\Python36
最好添加到Path,也可以不加

2.在VSCode市場中安裝Python插件

VSCode下如何配置python調(diào)試運(yùn)行環(huán)境

3.同樣是打開一個(gè)文件夾,新建一個(gè).py文件(這樣容易識(shí)別項(xiàng)目,vscode就需要新建一個(gè)文件夾)
4.同樣是launch.json文件和tasks.json文件

launch.josn

{
 // 使用 IntelliSense 了解相關(guān)屬性。 
 // 懸停以查看現(xiàn)有屬性的描述。
 // 欲了解更多信息,請(qǐng)?jiān)L問: https://go.microsoft.com/fwlink/?linkid=830387
 "version": "0.2.0",
 "configurations": [
  {
   "name": "Python",
   "type": "python",
   "request": "launch",
   "stopOnEntry": false,//是否在第一條語句時(shí)程序停止,下面的這個(gè)選項(xiàng)都一樣
   "pythonPath": "C:/Python34/python",//可執(zhí)行文件路徑
   "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": false,
   "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": false,
   "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": false,
   "pythonPath": "${config:python.pythonPath}",
   "program": "${file}",
   "cwd": "",
   "console": "externalTerminal",
   "env": {},
   "envFile": "${workspaceRoot}/.env",
   "debugOptions": [
    "WaitOnAbnormalExit",
    "WaitOnNormalExit"
   ]
  },
  {
   "name": "Django",
   "type": "python",
   "request": "launch",
   "stopOnEntry": false,
   "pythonPath": "${config:python.pythonPath}",
   "program": "${workspaceRoot}/manage.py",
   "cwd": "${workspaceRoot}",
   "args": [
    "runserver",
    "--noreload",
    "--nothreading"
   ],
   "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"
  }
 ]
}

tasks.json

 {
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
   {
    "taskName": "echo",
    "type": "shell",
    "command": "C:\\Python34\\python",//Python可執(zhí)行文件路徑
    "args": ["${file}"]
   }
  ]
 }

4.在用戶設(shè)置里加兩條

settings.json

 "python.pythonPath": "C:\\Python34\\python" ,//路徑
 "python.linting.enabled": false,//忘了是什么東西了,反正有用

Linting (Prospector, Pylint, pycodestyle, Flake8, pylama, pydocstyle, mypy with config files and plugin

靜態(tài)代碼掃描(可以理解為代碼語法和格式錯(cuò)誤提示,支持多種linter)

5.接下來是正式的調(diào)試了

VSCode下如何配置python調(diào)試運(yùn)行環(huán)境

默認(rèn)是Python選項(xiàng)
按\(<F5>\)啟動(dòng)調(diào)試
然后在

VSCode下如何配置python調(diào)試運(yùn)行環(huán)境

中有一些東西就是這樣
但是這個(gè)默認(rèn)的\(python\)選項(xiàng)并不能由用戶輸入
所以有

VSCode下如何配置python調(diào)試運(yùn)行環(huán)境

這個(gè)和下面的那個(gè)都可以
這個(gè)Intergrated……的選項(xiàng)是下圖的東東

VSCode下如何配置python調(diào)試運(yùn)行環(huán)境

其實(shí)這個(gè)可以直接

VSCode下如何配置python調(diào)試運(yùn)行環(huán)境

直接當(dāng)成cmd來用同樣可以由用戶輸入
然后那個(gè)External……的選項(xiàng)只不過是開了一個(gè)控制臺(tái)窗口

VSCode下如何配置python調(diào)試運(yùn)行環(huán)境

2333……
剩下的可以自己試試
說不定有驚喜

翻出很久之前做的一道題目
用py3寫的
剛剛一直在用的test.py就是用的這道題的代碼

1080 兩個(gè)數(shù)的平方和

基準(zhǔn)時(shí)間限制:1 秒 空間限制:131072 KB 分值: 5
給出一個(gè)整數(shù)N,將N表示為2個(gè)整數(shù)i j的平方和(i <= j),如果有多種表示,按照i的遞增序輸出。
例如:

(注:3 11同11 3算1種)

Input

一個(gè)數(shù)N()

Output

共K行:每行2個(gè)數(shù),i j,表示。
如果無法分解為2個(gè)數(shù)的平方和,則輸出

Input示例

130

Output示例

3 11
7 9

以上是“VSCode下如何配置python調(diào)試運(yùn)行環(huán)境”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI