In the editor, pressto open the extension marketplace and search and install the Python extension by Microsoft.
Poetry allows you to quickly create a Python boilerplate project with. Alternatively, if you prefer to use your own folder structure or already have an existing project, run inside your project.
With your project opened in VS Code, open a new terminal by pressingand run to create a virtual environment. VS Code will ask you if you want to set it up as the project's environment - say yes. This setting will be saved inside the file - you usually want to add this to your
Close the terminal window. Now every time you open a new terminal with anyfile open in the editor, VS Code will automatically activated the virtual environment in that shell. Try that now!
Make sure you're in a virtual environment-activated shell by following the step above, then runto install the Black formatter as a development dependency
All set! You can format the existing document by pressing, or enable from VS Code's settings. Make sure that Black is selected as Python's formatting provider in the extension settings.
By default, Black formats code with a maximum line length of 88 characters. You might want to enable a ruler in yourfile just for python files to visualize this. If you want, you can modify the maximum line length by adding the parameter to the list of Black arguments. Press to open the command palette and search and select "Preferences: Opens Settings (Json)". Then add your proffered options:
Thanks to poetry, the project's dependencies are tracked nicely in thefile. When distributing your script, it might be a good idea to instruct your users to use when installing dependencies to skip over the development packages. On top of that, you might want to generate a file anyway so that users without poetry can install the dependencies for your project as well. You can do this by running