Skip to content

Instantly share code, notes, and snippets.

@tabrez
Last active December 9, 2023 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabrez/b24c1f43e95ac51f141a22ddea4b5afb to your computer and use it in GitHub Desktop.
Save tabrez/b24c1f43e95ac51f141a22ddea4b5afb to your computer and use it in GitHub Desktop.
How to configure vs code for python development
  • Download & Install VSCode for Linux

  • Create a python virtual environment using mamba or python:

    cd/mkdir <project-dir>
    python -v venv .venv
    source activate .venv/bin/activate
  • Install packages using mamba or pip after creating and activating a virtual environment:

    • black: pip install black
    • autopep8: pip install autopep8 # Alternative to black
    • 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 in pyproject.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"
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment