Python & Visual Studio Code (Mac) - bradsorour/notes GitHub Wiki
A great tutorial on setting up a Python development environment in VSCode on MacOS:
Visual Studio Code (Mac) - Setting up a Python Development Environment and Complete Overview
-
Intall the Python Extension from within VS Code
-
To change the Python interpreter in VS Code use the Settings Gear icon in bottom left corner.
-
To open the Command Pallette, use
ctrl + cmd + P -
To access default settings, open the Command Palette and type
Default Settings -
To see which version of Python you are using, type
which python3into the VS Code terminal
In a VC Code terminal window, type the following command python3 -m venv venv
To use this virtual environment, select this from the Settings icon in the bottom left corner.
In a terminal run the following command pip install <package>
To format your code use the command shift + alt + F
To sort imports, open the Command Palette and type Sort Imports. This will arrange imports.
Install AYU from the Extensions for a better file icon theme.
So we don't have to right-click and use the command 'Run Python File in Terminal' to run our program, install the extension called Code Runner. This will allow you to run the program using the Play button in the top right corner.
The Code Runner keyboard shortcut is ctrl + alt + N.
For any input, you need to use the command 'Run Python File in Terminal'. You cannot use Code Runner, as it's for read-only.
From the VS Code terminal, run the following commands:
-
$ git init -
Create a
.gitignorefile and add the following:
venv
.vscode
-
$ git add . -
$ git commit -m "initial commit" -
$ git remote add origin <name-of-copied-github-repository-url> -
$ git push origin master
{
"editor.fontSize": 16,
"editor.minimap.enabled": false,
"window.zoomLevel": -1,
"python.dataScience.sendSelectionToInteractiveWindow": true,
"python.linting.pylintArgs": [
"--generate-members"
],
"workbench.settings.editor": "json",
"workbench.settings.openDefaultSettings": true,
"workbench.settings.useSplitJSON": true,
"python.pythonPath": "/usr/local/bin/python3",
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"code-runner.executorMap": {
"python": "$pythonPath -u $fullFileName"
},
"code-runner.showExecutionMessage": false,
"code-runner.clearPreviousOutput": true,
"workbench.iconTheme": "ayu",
"terminal.integrated.fontSize": 15
}