vscode 配置 python3開發(fā)環(huán)境的方法
vscode來(lái)寫python,配置靈活,界面美觀,是個(gè)非常好的選擇。我這里是在ubuntu系統(tǒng)下配置vscode的python3開發(fā)環(huán)境,當(dāng)然也可以參照本文在其它操作系統(tǒng)下配置vscode的python開發(fā)環(huán)境。
1 安裝插件
python
這個(gè)是vscode提供的python 官方插件,提供了python代碼的調(diào)試,自動(dòng)補(bǔ)全,代碼格式化等功能
vscode-icons
這個(gè)也是vscode官方提供的插件,作用是給vscode編輯的文件增加圖標(biāo)。這里再推薦一個(gè)相同功能的插件**vscode-icons-mac
**,文件圖標(biāo)變成Mac風(fēng)格,相當(dāng)美觀。
Path Intellisense
這個(gè)插件的作用是當(dāng)代碼中讀入文件名或者文件路徑時(shí),提供文件名或者文件路徑的自動(dòng)補(bǔ)全
topper
這個(gè)插件的作用是在.py
w文件的開頭添加一些說(shuō)明header
Bracket Pair Colorizer
這個(gè)插件的作用是給代碼中的括號(hào)增加顏色,同一對(duì)括號(hào)是相同的顏色,尤其是在括號(hào)中還包著括號(hào)的時(shí)候,看起來(lái)更加的清晰。
2 配置
可以在 這里下載我的配置文件,直接放在自己的python工作空間中。windows下的用戶可以這里下載我的配置文件。
2.1 建立Python文件夾
vscode 是基于文件夾的編輯器,我們可以首先建立一個(gè)文件夾叫做PYTHON
,作為我們的Python編程工作空間,只要一次配置好了這個(gè)工作空間,以后這個(gè)工作空間的配置就會(huì)對(duì)它之下的所有的.py
文件都起作用。
打開vscode,點(diǎn)擊左上角文件
—> 打開文件夾
,然后打開剛剛建立的PYTHON
文件夾。
然后我們點(diǎn)擊PYTHON
文件夾右邊的添加文件
按鈕:
添加一個(gè).py
文件,名字叫做hellovscode.py
.
2.2 配置launch.json 文件
點(diǎn)擊菜單欄調(diào)試
—> 打開配置
,就會(huì)彈出一個(gè)選擇框,我們?cè)谶@里要選擇Python
,然后就打開了launch.json
文件:
我們看到的launch.json
文件中的內(nèi)容如上圖所示。同時(shí)我們還發(fā)現(xiàn),在python工作區(qū)PYTHON
下面還多了一個(gè)文件夾.vscode
, 而且launch.json
就在這個(gè)文件夾中。
對(duì)launch.json
文件的配置如下:
在"configurations": []
z中,對(duì)于第一個(gè){ }內(nèi)的內(nèi)容修改如下:
{ "version": "0.2.0", "configurations": [ { "name": "Python3", "type": "python", "request": "launch", "stopOnEntry": false, "pythonPath": "/usr/bin/python3", //python3的安裝路徑 "program": "${file}", "cwd": "${workspaceFolder}", "env": {}, "envFile": "${workspaceFolder}/.env", "debugOptions": [ "RedirectOutput" ] } ] }
后面幾個(gè){ }中的內(nèi)容修改如下:
{ "name": "Python: Terminal (integrated)", "type": "python", "request": "launch", "stopOnEntry": false, "pythonPath": "/usr/bin/python3", "program": "${file}", "cwd": "", "console": "integratedTerminal", "env": {}, "envFile": "${workspaceFolder}/.env", "debugOptions": [] }, { "name": "Python: Terminal (external)", "type": "python", "request": "launch", "stopOnEntry": false, "pythonPath": "/usr/bin/python3", "program": "${file}", "cwd": "", "console": "externalTerminal", "env": {}, "envFile": "${workspaceFolder}/.env", "debugOptions": [] }, { "name": "Python: Django", "type": "python", "request": "launch", "stopOnEntry": true, "pythonPath": "/usr/bin/python3", "program": "${workspaceFolder}/manage.py", "cwd": "${workspaceFolder}", "args": [ "runserver", "--noreload", "--nothreading" ], "env": {}, "envFile": "${workspaceFolder}/.env", "debugOptions": [ "RedirectOutput", "Django" ] },
其它地方都不用修改。
2.3 配置tasks.json 文件
點(diǎn)擊菜單欄任務(wù)
—> 配置任務(wù)
,就會(huì)彈出一個(gè)選擇框,我們?cè)谶@里要選擇使用模板創(chuàng)建tasks.json文件
,然后又彈出一個(gè)選擇框,這里選擇Others
,就打開了tasks.json
文件:
對(duì)tasks.json
文件的配置如下:
{ "version": "2.0.0", "tasks": [ { "label": "python3", "type": "shell", "command": "/usr/bin/python3", "args": ["${file}"] } ] }
2.4 用戶設(shè)置
點(diǎn)擊菜單欄文件
—> 首選項(xiàng)
—> 設(shè)置
,然后打開用戶設(shè)置
:
用戶設(shè)置如下:
{ "git.ignoreLegacyWarning": true, "workbench.iconTheme": "vscode-icons", //啟用vscode圖標(biāo) "python.pythonPath": "/usr/bin/python3", // python3路徑 "editor.lineHeight": 26, // 編輯器中的行高 "editor.fontSize": 18, // 編輯器中的字體 "editor.wordWrap": "on", "editor.formatOnSave": true, //編輯器自動(dòng)保存 "python.linting.flake8Enabled": true, //啟用flake8,首先需要pip3 install falke8 "python.formatting.provider": "yapf", ///啟用yapf,首先需要pip3 install 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" ],// 忽略的警告信息 // 下面是topper的插入header配置 "topper.customTemplateParameters": [ { "personalProfile": { "author": "你的名字", "website": "bulbasaur.github.bitbucket.yababbdadado.com", "copyright": "None \n None", "license": "None", "email": "你的郵箱" } }, { "officeProfile": { "author": "John Doe", "department": "Product Development", "email": "john.doe@doejohn.com" } } ], "topper.headerTemplates": [ { "defaultCStyled": { "headerBegin": "/**", "headerPrefix": "*", "headerEnd": "*/", "template": [ "${headerBegin}", "${headerPrefix} ${fileName}", "${headerPrefix} @author ${author}", "${headerPrefix} @description ${description}", "${headerPrefix} @created ${createdDate}", "${headerPrefix} @copyright ${copyright}", "${headerPrefix} @last-modified ${lastModifiedDate}", "${headerEnd}" ] } }, { "python": { "headerBegin": "# -*- coding: utf-8 -*-", "headerPrefix": "#", "headerEnd": "#", "template": [ "${headerBegin}", "${headerPrefix} ${fileName}", "${headerPrefix} @author ${author}", "${headerPrefix} @description ${description}", "${headerPrefix} @created ${createdDate}", "${headerPrefix} @last-modified ${lastModifiedDate}", "${headerEnd}" ] } } ], "editor.fontFamily": "monospace", "terminal.integrated.fontFamily": "monospace", "editor.fontWeight": "500", }
接下來(lái)為topper配置一個(gè)快捷鍵以便于在python文件中快速插入文件header。
打開文件
->首選項(xiàng)
->鍵盤快捷方式
:
在搜索框輸入topper
點(diǎn)擊要配置的命令,然后輸入想要設(shè)定的快捷鍵,例如我對(duì)topper.addTopHeader.persionalProfile
設(shè)置的快捷鍵為Crtl+T T
。
那么當(dāng)在一個(gè)python文件中按下Crtl+T T
時(shí),就會(huì)插入header:
配置完畢,可以在vscode中愉快的寫python了。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python中實(shí)現(xiàn)對(duì)list做減法操作介紹
這篇文章主要介紹了Python中實(shí)現(xiàn)對(duì)list做減法操作介紹,需要的朋友可以參考下2015-01-01python Django連接MySQL數(shù)據(jù)庫(kù)做增刪改查
本文寫的是python Django連接MySQL數(shù)據(jù)庫(kù)的步驟,提供增刪改查的代碼2013-11-11Python一行代碼實(shí)現(xiàn)生成和讀取二維碼
二維碼被稱為快速響應(yīng)碼,可能看起來(lái)很簡(jiǎn)單,但它們能夠存儲(chǔ)大量數(shù)據(jù)。無(wú)論掃描二維碼時(shí)包含多少數(shù)據(jù),用戶都可以立即訪問信息。本文將用一行Python代碼實(shí)現(xiàn)二維碼的讀取與生成,需要的可以參考一下2022-02-02python的scipy.stats模塊中正態(tài)分布常用函數(shù)總結(jié)
在本篇內(nèi)容里小編給大家整理的是一篇關(guān)于python的scipy.stats模塊中正態(tài)分布常用函數(shù)總結(jié)內(nèi)容,有興趣的朋友們可以學(xué)習(xí)參考下。2021-02-02通過(guò)python3實(shí)現(xiàn)投票功能代碼實(shí)例
這篇文章主要介紹了通過(guò)python3實(shí)現(xiàn)投票功能代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09Python利用memory_profiler查看內(nèi)存占用情況
memory_profiler是第三方模塊,用于監(jiān)視進(jìn)程的內(nèi)存消耗以及python程序內(nèi)存消耗的逐行分析。本文將利用memory_profiler查看代碼運(yùn)行占用內(nèi)存情況,感興趣的可以了解一下2022-06-06