{ "created": "2022-04-12T13:41:50Z", "hierarchy": [ { "name": "ROOT", "type": "folder", "uri": "/ROOT" }, { "name": "Setting up VSCode for Python Development", "type": "article", "uri": "Setting_up_VSCode_for_Python_Development" } ], "html": "\n\n \n \n \n \n \n \n \n \n \n \n \n Setting up VSCode for Python Development – Nikhil's Personal Wiki\n \n \n \n \n \n
\n
\n \n
\n
\n \n \n\n

Setting up VSCode for Python Development\n \n

\n

A stupid-simple, barebones setup using:

\n\n

Written for macOS since that’s what most of our devs use. Paths and shortcuts will vary for Windows and Linux.

\n

Using this guide will help VSCode warn you of problematic code via red squiggles. You can then get an explanation via the “Problems” panel (Cmd+Shift+m.)

\n

In a Terminal

\n
# Install poetry globally in your Python (which you should\n# manage with pyenv)\npip install poetry\n\n# Create a new project\npoetry new my_project\n\n# Install these as development dependencies. Which they are.\npoetry add black flake8 isort pytest --dev\n

In VSCode

\n

Tell VSCode where all the virtual environments are

\n

On a Mac, type Cmd+Shift+p to pull up the Command Palette. Search for python.venvPath and set it to

\n
~/Library/Caches/pypoetry/virtualenvs\n
\n

Set the Python Interpreter to point at the Virtual Environment

\n

Type “Python Interpreter” in the Command Palette, hit enter, and pick something that looks like my_project-33ebFI0f-py3.9. You can see exactly which one by typing this in the terminal:

\n
poetry env info -p\n

For the next steps, and on a Mac, type Cmd+, to open up your Editor Settings.

\n

Use black

\n

Search for python.formatting.provider and choose black.

\n

You might like to format automagically on save. To do this, search for editor.formatOnSave.

\n

Use isort

\n

Nothing to do! Cmd+Shift+p and type “sort imports”.

\n

Use flake8

\n

Search for python.linting.flake8Enabled and enable Flake8.

\n

Use pytest

\n

Search for python.testing.pytestEnabled and enable PyTest. You’ll see a new “Beaker” icon in the Activity sidebar. Click it to see all the tests. VSCode has pretty powerful testing setup and discovery options you might be interested in.

\n

Use mypy

\n

Search for python.linting.mypyEnabled and enable MyPy.

\n
\n

The setup above should give you a nice Borg-like experience with Python development but you can make things even better using proprietary closed-source software!

\n

PyLance

\n

This is a language server for Python and is the intelligence in IntelliSense.

\n

To install, just get it from the VSCode Marketplace. It won’t work out of the box until you add this to .vscode/settings.json[1] in your project root.

\n
{\n    "python.analysis.useImportHeuristic": true\n}\n
\n

Now enjoy the awesome benefits of a language server. E.g. If you’re on macOS and a symbol doesn’t resolve, Cmd+. is your friend.

\n

Note: That setting above is in beta so you may have to type “Restart: Python Language Server” once in a while in the Command Palette if you get yellow squigglies that don’t go away EVEN THOUGH YOU KNOW YOU RIGHT, BOO đŸ˜¤

\n

ReWrap

\n

Install this extension. Then make sure you have 79 in the array of rulers in editor.rulers in your VSCode Settings. Now (on a Mac) press Option+q to rewrap (ha) comments to fit into 79 columns.

\n

And Finally!

\n

Exclude some unnecessary things in your sidebar. Pull up your VSCode settings (Command+, on macOS) and add these patterns

\n
**/__pycache__\n**/.pytest_cache\n
\n
\n

[1]: DO NOT CHECK THAT FILE AND FOLDER INTO SOURCE CONTROL.

\n\n\n
\n \n
\n \n \n \n \n \n\n", "id": "e19edce1-2761-5ad3-9c48-4fa902f6a4cf", "modified": "2024-04-15T23:13:03Z", "revisions": [ { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2024-04-15T23:13:03Z", "id": "1f343266dce411121f0cff3ca7e3e0632be6ce97", "shortId": "1f343266", "subject": "Some more notes\n", "content": "A stupid-simple, barebones setup using:\n\n* `poetry` for virtual environments\n* `black` for formatting and `isort` for import sorting\n* `flake8` for linting\n* `pytest` for testing\n* `mypy` for type-checking\n* (Optional but recommended) `pylance` for IntelliSenseâ„¢\n* (Optional but recommended) `rewrap` extension for docstrings and comments\n\n**Written for macOS** since that's what _most_ of our devs use. Paths and shortcuts will vary for Windows and Linux.\n\nUsing this guide will help VSCode warn you of problematic code via red squiggles. You can then get an explanation via the \"Problems\" panel (Cmd+Shift+m.)\n\n### In a Terminal\n\n```bash\n# Install poetry globally in your Python (which you should\n# manage with pyenv)\npip install poetry\n\n# Create a new project\npoetry new my_project\n\n# Install these as development dependencies. Which they are.\npoetry add black flake8 isort pytest --dev\n```\n\n### In VSCode\n\n#### Tell VSCode where all the virtual environments are\n\nOn a Mac, type Cmd+Shift+p to pull up the [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette). Search for `python.venvPath` and set it to\n\n ~/Library/Caches/pypoetry/virtualenvs\n\n#### Set the Python Interpreter to point at the Virtual Environment\n\nType \"Python Interpreter\" in the Command Palette, hit enter, and pick something that looks like `my_project-33ebFI0f-py3.9`. You can see _exactly_ which one by typing this in the terminal:\n\n```bash\npoetry env info -p\n```\n\nFor the next steps, and on a Mac, type Cmd+, to open up your Editor Settings.\n\n#### Use `black`\n\nSearch for `python.formatting.provider` and choose black. \n\nYou might like to format automagically on save. To do this, search for `editor.formatOnSave`.\n\n#### Use `isort`\n\nNothing to do! Cmd+Shift+p and type \"sort imports\".\n\n#### Use `flake8`\n\nSearch for `python.linting.flake8Enabled` and enable Flake8.\n\n#### Use `pytest`\n\nSearch for `python.testing.pytestEnabled` and enable PyTest. You'll see a new \"Beaker\" icon in the Activity sidebar. Click it to see all the tests. VSCode has pretty powerful testing setup and discovery options [you might be interested in](https://code.visualstudio.com/docs/python/testing).\n\n#### Use `mypy`\n\nSearch for `python.linting.mypyEnabled` and enable MyPy.\n\n---\n\nThe setup above should give you a nice Borg-like experience with Python development but you can make things even better using proprietary closed-source software!\n\n#### PyLance\n\nThis is a language server for Python and is the intelligence in IntelliSense.\n\nTo install, just get it from the VSCode Marketplace. It won't work out of the box until you add this to `.vscode/settings.json`[1] in your project root.\n\n```\n{\n \"python.analysis.useImportHeuristic\": true\n}\n```\n\nNow enjoy the awesome benefits of a language server. E.g. If you're on macOS and a symbol doesn't resolve, Cmd+. is your friend.\n\n**Note**: That setting above is in beta so you may have to type \"Restart: Python Language Server\" once in a while in the Command Palette if you get yellow squigglies that don't go away EVEN THOUGH _YOU_ KNOW _YOU_ RIGHT, BOO đŸ˜¤\n\n#### ReWrap\n\n[Install this extension](https://marketplace.visualstudio.com/items?itemName=stkb.rewrap). Then make sure you have `79` in the array of rulers in `editor.rulers` in your VSCode Settings. Now (on a Mac) press Option+q to rewrap (ha) comments to fit into 79 columns.\n\n#### And Finally!\n\nExclude some unnecessary things in your sidebar. Pull up your VSCode settings (Command+, on macOS) and add these patterns\n\n```\n**/__pycache__\n**/.pytest_cache\n```\n\n---\n\n[1]: DO NOT CHECK THAT FILE AND FOLDER INTO SOURCE CONTROL.\n" }, { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2022-04-12T13:41:50Z", "id": "cfd363f88bfaed2b4a831904c7327ac7a4e5200d", "shortId": "cfd363f8", "subject": "Create Setting up VSCode for Python Development.md", "content": "A stupid-simple, barebones setup using:\n\n* `poetry` for virtual environments\n* `black` for formatting and `isort` for import sorting\n* `flake8` for linting\n* `pytest` for testing\n* `mypy` for type-checking\n* (Optional but recommended) `pylance` for IntelliSenseâ„¢\n* (Optional but recommended) `rewrap` extension for docstrings and comments\n\n**Written for macOS** since that's what _most_ of our devs use. Paths and shortcuts will vary for Windows and Linux.\n\nUsing this guide will help VSCode warn you of problematic code via red squiggles. You can then get an explanation via the \"Problems\" panel (Cmd+Shift+m.)\n\n### In a Terminal\n\n```bash\n# Install poetry globally in your Python (which you should\n# manage with pyenv)\npip install poetry\n\n# Create a new project\npoetry new my_project\n\n# Install these as development dependencies. Which they are.\npoetry add black flake8 isort pytest --dev\n```\n\n### In VSCode\n\n#### Tell VSCode where all the virtual environments are\n\nOn a Mac, type Cmd+Shift+p to pull up the [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette). Search for `python.venvPath` and set it to\n\n ~/Library/Caches/pypoetry/virtualenvs\n\n#### Set the Python Interpreter to point at the Virtual Environment\n\nType \"Python Interpreter\" in the Command Palette, hit enter, and pick something that looks like `my_project-33ebFI0f-py3.9`. You can see _exactly_ which one by typing this in the terminal:\n\n```bash\npoetry env info -p\n```\n\nFor the next steps, and on a Mac, type Cmd+, to open up your Editor Settings.\n\n#### Use `black`\n\nSearch for `python.formatting.provider` and choose black. \n\nYou might like to format automagically on save. To do this, search for `editor.formatOnSave`.\n\n#### Use `isort`\n\nNothing to do! Cmd+Shift+p and type \"sort imports\".\n\n#### Use `flake8`\n\nSearch for `python.linting.flake8Enabled` and enable Flake8.\n\n#### Use `pytest`\n\nSearch for `python.testing.pytestEnabled` and enable PyTest. You'll see a new \"Beaker\" icon in the Activity sidebar. Click it to see all the tests. VSCode has pretty powerful testing setup and discovery options [you might be interested in](https://code.visualstudio.com/docs/python/testing).\n\n#### Use `mypy`\n\nSearch for `python.linting.mypyEnabled` and enable MyPy.\n\n---\n\nThe setup above should give you a nice Borg-like experience with Python development but you can make things even better using proprietary closed-source software!\n\n#### PyLance\n\nThis is a language server for Python and is the intelligence in IntelliSense.\n\nTo install, just get it from the VSCode Marketplace. It won't work out of the box until you add this to `.vscode/settings.json`[1] in your project root.\n\n```\n{\n \"python.analysis.useImportHeuristic\": true\n}\n```\n\nNow enjoy the awesome benefits of a language server. E.g. If you're on macOS and a symbol doesn't resolve, Cmd+. is your friend.\n\n**Note**: That setting above is in beta so you may have to type \"Restart: Python Language Server\" once in a while in the Command Palette if you get yellow squigglies that don't go away EVEN THOUGH _YOU_ KNOW _YOU_ RIGHT, BOO đŸ˜¤\n\n#### ReWrap\n\n[Install this extension](https://marketplace.visualstudio.com/items?itemName=stkb.rewrap). Then make sure you have `79` in the array of rulers in `editor.rulers` in your VSCode Settings. Now (on a Mac) press Option+q to rewrap (ha) comments to fit into 79 columns.\n\n#### And Finally!\n\nExclude some unnecessary things in your sidebar. Pull up your VSCode settings (Command+, on macOS) and add these patterns\n\n```\n**/__pycache__\n**/.pytest_cache\n```\n\n---\n\n[1]: DO NOT CHECK THAT FILE AND FOLDER INTO SOURCE CONTROL.\n" } ], "sizeInBytes": 3827, "source": "A stupid-simple, barebones setup using:\n\n* `poetry` for virtual environments\n* `black` for formatting and `isort` for import sorting\n* `flake8` for linting\n* `pytest` for testing\n* `mypy` for type-checking\n* (Optional but recommended) `pylance` for IntelliSenseâ„¢\n* (Optional but recommended) `rewrap` extension for docstrings and comments\n\n**Written for macOS** since that's what _most_ of our devs use. Paths and shortcuts will vary for Windows and Linux.\n\nUsing this guide will help VSCode warn you of problematic code via red squiggles. You can then get an explanation via the \"Problems\" panel (Cmd+Shift+m.)\n\n### In a Terminal\n\n```bash\n# Install poetry globally in your Python (which you should\n# manage with pyenv)\npip install poetry\n\n# Create a new project\npoetry new my_project\n\n# Install these as development dependencies. Which they are.\npoetry add black flake8 isort pytest --dev\n```\n\n### In VSCode\n\n#### Tell VSCode where all the virtual environments are\n\nOn a Mac, type Cmd+Shift+p to pull up the [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette). Search for `python.venvPath` and set it to\n\n ~/Library/Caches/pypoetry/virtualenvs\n\n#### Set the Python Interpreter to point at the Virtual Environment\n\nType \"Python Interpreter\" in the Command Palette, hit enter, and pick something that looks like `my_project-33ebFI0f-py3.9`. You can see _exactly_ which one by typing this in the terminal:\n\n```bash\npoetry env info -p\n```\n\nFor the next steps, and on a Mac, type Cmd+, to open up your Editor Settings.\n\n#### Use `black`\n\nSearch for `python.formatting.provider` and choose black. \n\nYou might like to format automagically on save. To do this, search for `editor.formatOnSave`.\n\n#### Use `isort`\n\nNothing to do! Cmd+Shift+p and type \"sort imports\".\n\n#### Use `flake8`\n\nSearch for `python.linting.flake8Enabled` and enable Flake8.\n\n#### Use `pytest`\n\nSearch for `python.testing.pytestEnabled` and enable PyTest. You'll see a new \"Beaker\" icon in the Activity sidebar. Click it to see all the tests. VSCode has pretty powerful testing setup and discovery options [you might be interested in](https://code.visualstudio.com/docs/python/testing).\n\n#### Use `mypy`\n\nSearch for `python.linting.mypyEnabled` and enable MyPy.\n\n---\n\nThe setup above should give you a nice Borg-like experience with Python development but you can make things even better using proprietary closed-source software!\n\n#### PyLance\n\nThis is a language server for Python and is the intelligence in IntelliSense.\n\nTo install, just get it from the VSCode Marketplace. It won't work out of the box until you add this to `.vscode/settings.json`[1] in your project root.\n\n```\n{\n \"python.analysis.useImportHeuristic\": true\n}\n```\n\nNow enjoy the awesome benefits of a language server. E.g. If you're on macOS and a symbol doesn't resolve, Cmd+. is your friend.\n\n**Note**: That setting above is in beta so you may have to type \"Restart: Python Language Server\" once in a while in the Command Palette if you get yellow squigglies that don't go away EVEN THOUGH _YOU_ KNOW _YOU_ RIGHT, BOO đŸ˜¤\n\n#### ReWrap\n\n[Install this extension](https://marketplace.visualstudio.com/items?itemName=stkb.rewrap). Then make sure you have `79` in the array of rulers in `editor.rulers` in your VSCode Settings. Now (on a Mac) press Option+q to rewrap (ha) comments to fit into 79 columns.\n\n#### And Finally!\n\nExclude some unnecessary things in your sidebar. Pull up your VSCode settings (Command+, on macOS) and add these patterns\n\n```\n**/__pycache__\n**/.pytest_cache\n```\n\n---\n\n[1]: DO NOT CHECK THAT FILE AND FOLDER INTO SOURCE CONTROL.\n", "title": "Setting up VSCode for Python Development", "untracked": false, "uri": "/Setting_up_VSCode_for_Python_Development", "relativePath": "Setting up VSCode for Python Development.md" }