E. How to Install Visual Studio Code (VS Code) and Get Started - ZamaZoe/1.-Kurro-REST-API-Tutorial_Introduction GitHub Wiki
Introduction
Welcome!
In this section, we will guide you on installing and setting up an Integrated Development Environment (IDE); we will set up Visual Studio Code (VS Code), an IDE that can also function as a text editor. We opted for this IDE for this tutorial as it offers extra features that simplify programming, although you're welcome to use any IDE you feel at ease with.
Prerequisite
Before you install the IDE, you must first install Python; if you still need to install it, please follow this link on How to Install Python. Below are the steps on how to install the IDE
The Steps to Install Visual Studio Code
- To download the Visual Studio Code setup, click on the following link: code.visualstudio.com.
- Then, select the file version related to your operating system, as shown in the screenshot below:
- Next, to install Visual Studio Code, double-click the file you downloaded.
- Follow the setup steps as shown in the following screenshots:
- After the installation setup finishes, another window will appear on your computer screen. Please complete the setup by selecting 'Finish' at the bottom of the screen.
Getting Started with VS Code
Introduction
We will write, run, and execute a simple Python program to get started with the Visual Studio Code IDE. We chose Python because we will build a REST API with Flask and Python for our tutorial project. If you still need to download Python on your computer, please click this link: Python Downloads. Below are the steps to create and run a Python program.
The Steps to Create and Run a Simple Python Program
Step 1: Follow these steps to create an empty folder for your project:
- Navigate to your file system in Windows Explorer or Mac Finder; create an empty folder from here. You may name this folder 'First_Python_Program.' In this folder, you will store your project files.
Step 2: Follow these steps to launch Visual Studio Code and get started:
- To launch the Visual Studio Visual IDE, locate the VS Code icon on your desktop and double-click on it.
- Select the 'Open Folder' tab from the file menu; refer to the screenshot below for guidance.
- Then, navigate to the empty folder created in step 1 (First_Python_Program) and select or double-click the folder; again, you could create a new folder in this tab if you did not follow step 1.
- The folder will open as the root directory for this project; should you get a warning stating, 'Do you trust the authors?' Please press 'Yes' to continue using that folder.
- Now, you are all set to write your first Python program.
Step 3: Use the following steps to create a text file:
We will create a text file within the IDE and write our first line of code in a Python program. Here are the steps to create a text file:
- Navigate to your folder. Select the first tab named 'New File;' enter the file's name, and you can call this file 'My_program.txt;' follow the example shown in the screenshots below:
Note:
- Dot py (.py) is the actual extension for Python programs, but it's not a requirement for this specific program.
- The basis for using dot-txt (.txt) files is to help you understand crucial Python concepts.
- For your filename, you must insert underscores between spaces.
Step 4: Use the following steps to write and execute your first Python program:
- Navigate to the file 'My_program.txt' we created in step 3 to write a Python program within an IDE. Write your first line of code, as shown in the following screen; this program will output the sum of '
3+4
.'
- To save the file, navigate to the menu bar, select the file tab, and click the 'Save' option; alternatively, you may type '
CTRL + S
' from your keyboard.
- To execute this program to get results, navigate to the menu bar and select the 'Terminal' tab, then select the option 'New Terminal' to open the command-line interface that interacts with your computer. See the following screenshots:
- Execute or run the following commands on the command-line interface:
- For Windows users, run this command: '
python My_program.txt
.' - For Mac users, run this command: '
python3 My_program.txt
.'
Results:
- Our program returned an output of 7. See the following screenshot:
Conclusion
- The key to the above steps aims to help you start with the Visual Studio Code (VS Code) IDE.
- Also, it helps you to comprehend that a Python program is akin to a text file. You write and execute it using the Python command.
- Now that we have installed Python and Visual Studio, let's create a virtual environment that we will use to build our REST API project. Follow this link to learn and create a virtual environment for your tutorial project: How to Create a Virtual Environment for Your REST API Tutorial Project