首先请大家确定vscode的安装以及python环境的配置安装已经完毕!【推荐学习:《vscode教程》】
首先进入扩展搜索,输入python搜索,点击如图所示的python插件进行安装并重启vscode。
检查python是否安装成功:
打开命令提示符输入 python 回车输入pip list 检查第三方包是否正确安装第三方包:
打开命令提示符输入 pip install flake8输入 pip install yapf这两个包在配置vscode的python环境时会用上1. 新建一个项目
新建一个文件 test.py
2.配置工作区域(配置flake8和yapf并关闭pylint工具)
配置如下代码:
{ "python.linting.flake8enabled": true, "python.formatting.provider": "yapf", "python.linting.flake8args": [ "--max--line-length=248" ], "python.linting.pylintenabled": false}
3.配置python编译设置
点击左侧的debug,选择添加配置,会弹出java,python,选择python会弹出launch.json文件
添加以下配置(这样编译时,可以不用按两次f5),如果你想一步一步地调试,将false改成true就行了"stoponentry":false,
4.环境变量的设置
完成以上配置并不能让我们在vscode中,调试和运行代码因为我们还没有配置vscode中的python路径打开 launch.json,在调试时使用的调试器下输入"pythonpath":目标路径"pythonpath": "你的pytho.exe所在的路径",
5.配置默认任务
完成这一步,可以直接通过快捷键得到程序的运行结果点开terminal(终端),选择configure default build task(配置默认生成任务),打开task.json文件
修改以下配置"group":{ "kind":"build", "isdefault":true }
6.补充配置
file -> preferences -> settings -> open setting.json
在 user setting.json中添加配置:{ "workbench.startupeditor": "newuntitledfile", "python.pythonpath": "你的python.exe路径", "python.linting.enabled": false, "editor.fontsize": 14}
7.保存修改,重启vscode,打开文件进行调试:
'''@name: sunny chen@test: test font@msg: 这是由sunny chen创建.@param: @return: '''list_a=[1,2]list_b=[5,6]ref_list_a=id(list_a)for i in range(1,6): for j in range(1,6): print(str(j)+"\n") print(str(i)+"\n")
更多编程相关知识,请访问:编程入门!!
以上就是vscode如何进行python开发?开发环境配置介绍的详细内容。
