-
Create a python virtual environment using
mamba
orpython
:cd/mkdir <project-dir> python -v venv .venv source activate .venv/bin/activate
-
Install packages using
mamba
orpip
after creating and activating a virtual environment:black
:pip install black
autopep8
:pip install autopep8
# Alternative toblack
ipython
:pip install ipython
ipykernel
:pip install ipykernel
jupyter
:pip install jupyter
ipywidgets
: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
python
extension for VS Code:
code --install-extension ms-python.python
All VS Code extensions can be installed from the Extensions
tab with-in VS Code also.
- Configure
black
inpyproject.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"
]