-
Create a python virtual environment using
mambaorpython:cd/mkdir <project-dir> python -v venv .venv source activate .venv/bin/activate
-
Install packages using
mambaorpipafter creating and activating a virtual environment:black:pip install blackautopep8:pip install autopep8# Alternative toblackipython:pip install ipythonipykernel:pip install ipykerneljupyter:pip install jupyteripywidgets:pip install ipywidgets
Alternatively, put the above package names in a requirements.txt file(one per line) and run: pip install -r requirements.txt
- Install
pythonextension for VS Code:
code --install-extension ms-python.pythonAll VS Code extensions can be installed from the Extensions tab with-in VS Code also.
- Configure
blackinpyproject.toml(in project's root directory):
[tool.black]
line-length = 88
include = '\.pyi?$'
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
'''- Black
Install VS Code extension: code --install-extension ms-python.black-formatter
Configure black in VS Code settings.json:
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}
"editor.formatOnSave": true- Pylance:
Install extension: code --install-extension ms-python.vscode-pylance
Configure pylance in VS Code settings.json:
"python.languageServer": "Pylance",
// "python.analysis.typeCheckingMode": "strict"- (Alternative to
black) Autopep8:
Install extension: code --install-extension ms-python.autopep8
Configure autopep8 in VS Code settings.json:
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
},
"editor.formatOnSave": true,
"python.formatting.autopep8Args": [
"--max-line-length=88",
"--ignore=E11",
"--select=W291,W293,W391"
]