vs code如何配置python,-Visual Studio Code配置Python环境和代码配色 - 0&#34

📅 2026-11-30 👤 拼多多助力营销技巧 📂 拼多多助力2027 👁️ 383 次阅读

一、Visual Studio Code配置Python环境

1、从Visual Studio Code官网下载VScode

Visual Studio Code官网地址https://code.visualstudio.com/Visual Studio Code傻瓜式安装,直接点击安装文件,然后一直点击下一步就可以了。软件是免费的,不需要费力破解。

2、从Python 官网下载PythonWelcome to Python.orghttps://www.python.org/

Python安装也是很简单的,唯一注意的是自动配置环境变量要勾选上。当然,没有勾选上也不要紧,那就是手动去配置环境变量了。

3、使用Python自带的pip下载第三方库

通过python自带的pip工具,安装两个一会儿配置VScode需要的第三方库。flake8和yapf flake8会检查编写代码时的不规范的地方和语法错误。yapf是一个代码格式化工具,可以一键美化代码。 安装过程如下:

在cmd输入pip list检查是否已存在需要的包输入pip install flake8下载安装flake8输入pip install yapf下载安装yapf

附:更新pip到最新版本 python -m pip install --upgrade pip

4、VScode中配置Python

ctrl+shift+x进到扩展商店中去搜索Python插件,第一个就是。

看不惯英文版,想汉化,也是在扩展商店里搜索Chinese,安装后关闭VScode,重进就好了。

先从磁盘中新建一个文件夹作为工作目录,命名之后就从VScode中打开这个文件夹,以后文件也都会存在这个文件夹下。可以先建立一个demo.py文件,用于我们最终的调试。

5、在运行里点击打开配置,配置launch.json文件。

{

"version": "0.2.0",

"configurations": [

{

"version": "0.2.0",

"configurations": [

{

"name": "Python3",

"type": "python",

"request": "launch",

"stopOnEntry": false,

"python": "C:\\Python39", //python3的安装路径!

"program": "${file}",

"cwd": "${workspaceFolder}",

"env": {},

"envFile": "${workspaceFolder}/.env",

"debugOptions": [

"RedirectOutput"

]

}

]

},

6、从左下角的管理里找到设置按钮,然后配置settings.json文件。

{

"git.ignoreLegacyWarning": true,

"workbench.iconTheme": "vscode-icons", //启用vscode图标

"python.*pythonPath*": "C:\\Python39", //

## python3路径,注意看我起的名字叫pythonPath,这个名字需要在环境变量里也配置一下!!!

"editor.lineHeight": 26, // 编辑器中的行高

"editor.fontSize": 18, // 编辑器中的字体

"editor.wordWrap": "on",

"editor.formatOnSave": true, //编辑器自动保存 拼多多帮助力入口

"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"

"terminal.integrated.fontFamily": "monospace",

"editor.fontWeight": "500",

"python.defaultInterpreterPath": "C:\\Python39",

}

7、Python终端报错

这时迫不及待的右键去运行demo.py文件了。不过很多人就卡在这里。***终端报错如下:

无法将“C:/Python39”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。

解决办法: 很多人都说配置环境变量,但是就是没说清楚怎么配置。我们需要起一个和VScode中配置的变量同名变量(我起的名字叫pythonPath),注意看下图的内容!!!然后变量后面写上我们的Python的地址。当然,Path中也需要配置python的地址。

二、修改VS code代码配色

设置 --> 文本编辑器 -->字体 -->Font Ligatures -->在json中打开

{

"terminal.explorerKind": "external",

"terminal.integrated.tabStopWidth": 4,

"files.autoSave": "onFocusChange",

"editor.fontSize": 16,

"editor.renderWhitespace": "all",

"prettier.tabWidth": 4,

"security.workspace.trust.untrustedFiles": "open",

"editor.mouseWheelZoom": true,

"editor.fontLigatures": false,

"terminal.integrated.fontSize": 18,

"screencastMode.fontSize": 60,

"editor.inlayHints.fontSize": 5,

"editor.suggestFontSize": 22,

"editor.codeLensFontSize": 18,

"chat.editor.fontSize": 20,

"scm.inputFontSize": 20,

"files.trimTrailingWhitespace": true,

"workbench.editor.wrapTabs": true,

"prettier.proseWrap": "always",

"C_Cpp.vcFormat.wrap.preserveBlocks": "never",

"editor.wordWrapColumn": 50,

"editor.tokenColorCustomizations": {

"comments": "#33970c",

"strings": "#208130", // 字符串

"keywords": "#6d75e2", // 关键字

// "variables": "#a792e2", // 变量名

"functions": "#9c337d", // 内置函数名

// "numbers": "#00eeff", // 数字

// "types": "#55bbff", //类定义颜色

}

}

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧