前言
日常工作中,我用的比较多的Python IDE就是Pycharm和VS Code了。Pycharm虽然内存占用大,但是不得不说真心好用。一些小的项目我就会换上VS Code,轻量级嘛,不过要在VS Code的中调试Python,需要安装Python插件。
Python插件
VS Code1.3版中对插件的安装做了调整,新增了安装面板,感觉比之前好用多了。直接搜索Python插件安装即可,它提供智能补全、函数跳转、DEBUG、Lint、自动格式化等常用功能。
VS Code.png配置
插件安装完后,我们可以在默认配置中发现下面一堆Python的配置。
// Python Configuration
// Path to Python, you can use a custom version of Python by modifying this setting to include the full path.
"python.pythonPath": "python",
// Whether to lint Python files.
"python.linting.enabled": true,
// Whether to lint Python files using prospector.
"python.linting.prospectorEnabled": false,
// Whether to lint Python files using pylint.
"python.linting.pylintEnabled": true,
// Whether to lint Python files using pep8
"python.linting.pep8Enabled": false,
// Whether to lint Python files using flake8
"python.linting.flake8Enabled": false,
// Whether to lint Python files using pydocstyle
"python.linting.pydocstyleEnabled": false,
// Whether to lint Python files when modified.
"python.linting.lintOnTextChange": true,
// Whether to lint Python files when saved.
"python.linting.lintOnSave": true,
// Controls the maximum number of problems produced by the server.
"python.linting.maxNumberOfProblems": 100,
// Severity of Pylint message type 'Convention/C'.
"python.linting.pylintCategorySeverity.convention": "Hint",
// Severity of Pylint message type 'Refactor/R'.
"python.linting.pylintCategorySeverity.refactor": "Hint",
// Severity of Pylint message type 'Warning/W'.
"python.linting.pylintCategorySeverity.warning": "Warning",
// Severity of Pylint message type 'Error/E'.
"python.linting.pylintCategorySeverity.error": "Error",
// Severity of Pylint message type 'Fatal/F'.
"python.linting.pylintCategorySeverity.fatal": "Error",
// Path to Prospector, you can use a custom version of prospector by modifying this setting to include the full path.
"python.linting.prospectorPath": "prospector",
// Path to Pylint, you can use a custom version of pylint by modifying this setting to include the full path.
"python.linting.pylintPath": "pylint",
// Path to pep8, you can use a custom version of pep8 by modifying this setting to include the full path.
"python.linting.pep8Path": "pep8",
// Path to flake8, you can use a custom version of flake8 by modifying this setting to include the full path.
"python.linting.flake8Path": "flake8",
// Path to pydocstyle, you can use a custom version of pydocstyle by modifying this setting to include the full path.
"python.linting.pydocStylePath": "pydocstyle",
// Arguments passed in. Each argument is a separate item in the array.
"python.linting.prospectorArgs": [],
// Arguments passed in. Each argument is a separate item in the array.
"python.linting.pylintArgs": [],
// Arguments passed in. Each argument is a separate item in the array.
"python.linting.pep8Args": [],
// Arguments passed in. Each argument is a separate item in the array.
"python.linting.flake8Args": [],
// Arguments passed in. Each argument is a separate item in the array.
"python.linting.pydocStyleArgs": [],
// The output window name for the linting messages, defaults to Python output window.
"python.linting.outputWindow": "Python",
// Provider for formatting. Possible options include 'autopep8' and 'yapf'.
"python.formatting.provider": "autopep8",
// Path to autopep8, you can use a custom version of autopep8 by modifying this setting to include the full path.
"python.formatting.autopep8Path": "autopep8",
// Path to yapf, you can use a custom version of yapf by modifying this setting to include the full path.
"python.formatting.yapfPath": "yapf",
// Arguments passed in. Each argument is a separate item in the array.
"python.formatting.autopep8Args": [],
// Arguments passed in. Each argument is a separate item in the array.
"python.formatting.yapfArgs": [],
// Format the document upon saving.
"python.formatting.formatOnSave": false,
// The output window name for the formatting messages, defaults to Python output window.
"python.formatting.outputWindow": "Python",
// List of paths to libraries and the like that need to be imported by auto complete engine. E.g. when using Google App SDK, the paths are not in system path, hence need to be added into this list.
"python.autoComplete.extraPaths": [],
// Whether to enable or disable unit testing using nosetests.
"python.unitTest.nosetestsEnabled": false,
// Path to nosetests, you can use a custom version of nosetests by modifying this setting to include the full path.
"python.unitTest.nosetestPath": "nosetests",
// Whether to enable or disable unit testing using pytest.
"python.unitTest.pyTestEnabled": false,
// Path to pytest, you can use a custom version of pytest by modifying this setting to include the full path.
"python.unitTest.pyTestPath": "pytest",
// Arguments passed in. Each argument is a separate item in the array.
"python.unitTest.nosetestArgs": [],
// Arguments passed in. Each argument is a separate item in the array.
"python.unitTest.pyTestArgs": [],
// Arguments passed in. Each argument is a separate item in the array.
"python.unitTest.unittestArgs": [],
// Whether to enable or disable unit testing using standard unittest (built into Python).
"python.unitTest.unittestEnabled": true,
// The output window name for the unit test messages, defaults to Python output window.
"python.unitTest.outputWindow": "Python",
我一般会在用户配置或者项目配置中设置下面几项:
"python.pythonPath": "python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
// lint使用pep8
"python.linting.pep8Enabled": true,
// 如果使用virtualenv的话,可能要指定具体路径
"python.linting.pep8Path": "pep8",
"python.linting.lintOnSave": true,
"python.formatting.provider": "yapf",
// 同样,使用virtualenv的话,要指定具体路径
"python.formatting.yapfPath": "yapf"
记得pip安装pep8和yapf,豆瓣源https://pypi.douban.com/simple
DEBUG
Python插件的debug和nodejs是类似的,都不要一个launch.json的配置,分为Python、Python Console App 、Django和Watson。
我一般就用Python的。
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "python",
"program": "${workspaceRoot}/runserver.py",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
}
如果使用的是virtualenv或者其他不适默认Python路径的,需要指定pythonPath。
然后就可以愉快的开始DEBUG了。
结语
其实不管是什么IDE都只是工具而已,可能有些用的熟了是能提高工作效率,但是提高的工作效率是否能弥补真正的能力,我也不知道了。。。
最后,如果想过滤掉.pyc文件和.git目录或者其他一些文件或者目录的,请使用files.exclude配置。
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.DS_Store": true,
"**/*.pyc": true
}
网友评论