Using VSCode with Python
By Richard Porteous
Setting up Visual Studio Code for Python development
If on windows Install the powershell & terminal from microsoft store or the website first. The default ones on Windows 10/11 are old. You may need to set them as defaults.
Here are the steps for a fresh install
- Install Python
- Install Visual Studio Code
- Install the Python Extension
You may need to Install older versions if you plan on using Windows 7
Install Python for your OS:
Download and install Python Use the install suggestions.
I found when installing on windows I use the following options.
Notepad as the editor, the windows command prompt, and the support for long names, and finally allow it to add the path to your environment variables.
Beginners See also https://wiki.python.org/moin/BeginnersGuide
Take a look at my Learning Guide which will point you to free resources
Install VSCode:
Download and install Visual Studio Code from the official website
or
Download and Install VSCodium which is the open source project Microsoft uses their website is vscodium.com
Open VSCode/VSCodium after installation
Navigate to the Extensions panel on the left-hand side in VSCode Search for the “Python” extension and install it
At this Point you should likely restart your computer to see option show up in windows explorer like run “code from here” or “run terminal from here”
Create a Python Project:
You can do also this from VSCode
Open or create a folder where you want to work on your Python project. I usually have a dev/development folder in my user folder.
- Install a virtual environment ( see Virtual Environment ) if it doesn’t already exist
mkdir projectA
cd projectA
python3.8 -m venv env
free code camp has instructions if you need detail
- Create a new Python file with the .py extension
From VSCode you need to open your project folder - or using windows explorer You can add a file from the ’new file’ option on the left
Name the file game.py
Write and Run Python Code:
Start coding! Write your Python code in the newly created file. See worm series
You can run the code using the run button, the terminal, or the interactive window
Debug Your Python Code:
Set breakpoints and debug your Python code using the debugger Customize debugger settings in the launch.json file
Install Packages:
Use the integrated terminal to install Python packages using pip Remember to explore additional resources to get the most out of Python in Visual Studio Code! If you’re new to programming, consider checking out the Visual Studio Code for Education - Introduction to Python course²4. Happy coding! 🐍💻
References
Source: Conversation with Bing, 2024-04-29
(1) How to set up Visual Studio Code for Python development - The Teclado Blog
(2) Get Started Tutorial for Python in Visual Studio Code
- [How to set up Python on Visual Studio Code (YouTube)] (https://www.youtube.com/watch?v=9o4gDQvVkLU)
(4) [How To Setup Python for VSCode | Setting Up VSCode For Python Programming (YouTube)] (https://www.youtube.com/watch?v=oSmEIr3yBL0)
(5) [Setting Up VSCode For Python Programming (YouTube)] (https://www.youtube.com/watch?v=W--_EOzdTHk)
(6) [How to set up Python in VS Code? - Stack Overflow] (https://stackoverflow.com/questions/42472265/how-to-set-up-python-in-vs-code)
(7) [Python Development in Visual Studio Code (Setup Guide)] (https://realpython.com/courses/python-development-visual-studio-code-setup-guide/)
(8) [Getting Started with Python in Visual Studio Code | Python with VSCode (YouTube)] (https://www.youtube.com/watch?v=E9U-EBG8jVk)
(9) [Python in Visual Studio tutorial Step 1, create a project] (https://learn.microsoft.com/en-us/visualstudio/python/tutorial-working-with-python-in-visual-studio-step-01-create-project?view=vs-2022)
(10) [Install and configure Visual Studio Code for Python development] (https://learn.microsoft.com/en-us/training/modules/python-install-vscode/)
PS: I use DuckDuckGo as my search engine starting Nov 2024