写在最前面:
不得不说,windows下VS Code的黑比PyCharm下的黑要黑多了,默认字体也更棒,用来做些小的算法练习再合适不过了,大型项目还是上PyCharm吧。
首先下载VS Code
然后搜索python,点击install
然后我们需要修改两个文件
- 点击 VS Code 的 文件 > 首选项 > 设置 ,可以打开设置面板;
- 在 VS Code 中使用 Ctrl+Shift+P打开命令面板,输入Preferences: Open User Settings或Preferences: Open Workspace Settings。
一般来说,我们首先在某个盘建个文件夹,然后再VS Code中选择打开open folder,打开这个文件夹。此时该文件下会生产两个json文件,launch.json和settings.json。
配置如下:
settings.json:
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.pythonPath":"C:\\python3\\python"
}
选择你的python环境的路径
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
]
},
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "enter-your-module-name-here",
"console": "integratedTerminal"
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"console": "integratedTerminal",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"django": true
},
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "app.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
},
{
"name": "Python: Current File (External Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
}
]
}
添加一行 "pythonPath": "${config:python.pythonPath}",
然后一般我们需要装个pylint的插件,规范代码风格,然鹅,由于是内网,无法pip安装,那我们就手动安装。
在https://pypi.org/下载好wheel或者tar.gz的文件后,通过pip install xxx.wheel或者python setup.py install安装。
在settings.json中添加下面一行
"python.linting.pylintPath": "C:\\python3\\Scripts\\pylint.exe"