How to Install Python and Getting Started - ZamaZoe/1.-Kurro-REST-API-Tutorial_Introduction GitHub Wiki
Introduction
Here, you will get started with the Python setup; the setup is suitable for any personal computer; all you have to do is follow the instruction in the "How-to- Guide." We will begin this section by installing Python on Windows, Mac, and Linux PC.
This section will end with another introduction to Python from a computer science perspective; you will learn essential concepts and secrets about a programming language such as Python. Below are the steps to install Python.
The Steps to Install Python Program with Pip Package
- To download the latest version of Python, click on this link Download Python
- elect the file with the version related to your operating system, as shown in the screenshot below; for this tutorial, please download Python 3.10.10 version.
- For this tutorial, please download Python 3.10.10 version, as shown in the screenshot below:
- For Windows Download
- For macOS Download
- To install Python
- Double-click the file you downloaded.
- Then, in the installation window, tick the bottom box (add python.exe to PATH) as shown in the screenshot below.
- Select Install Now to Install Python.
- The installation status will appear in the following window. Please wait for it, as it may take a little time.
- The last step will show another window confirming Setup was successful. Now you are to create and run a python program.
The Steps to Create and Run a Python Program, Pt.1
Step1: Create an empty project folder:
- Go to your file system on Windows Explorer or Mac Finder
- From here, create an empty folder. You may name the folder "First_Python_Program." In this folder, you will store all your project files.
Step2: Getting started with Visual Studio Code:
- Open the Visual Studio Code.
- Select the "open folder" tab as shown in the screenshot below.
- Browse to the empty folder created in step1, "First_Python_Program".
- Select or double-click the folder; you could also create a new folder in this tab if you did not follow step 1.
- The folder will open as the project’s root directory.
- If you get a warning stating, "Do you trust the authors," Please select yes.
Results:
- In the screenshot shown below, you can see the project as the root directory; also, the folder’s name is the same as the project’s.
- Now, you are ready to write your first python program.
Step3: The Steps to Create a Text File:
Here, we will start by creating a text file within the IDE
- Go to your folder. Select the first tab, "New File." as shown in the screenshot below:
- Write the file’s name as shown in the screenshot below; you can name it "My_program.txt."
Note:
- The actual extension for the python program is “.py,” which is not a requirement for this program.
- The grounds for using dot txt is to help you understand crucial concepts about Python. Also, for your file name, you must use underscores between spaces.
Step4: Writing your first Python program:
- To write a python program. Press enter, and write "print(3+4)," as shown below. Please save the file; otherwise, this will not execute the program. This program will output the sum of 3+4.
Print(3+4)
- To save the file, go to the menu bar. Select the file tab, and click on the option, "Save;" alternatively, type "CTRL+S" from your keyboard.
- To execute this program to get results, go to the menu bar and select "Terminal," then select "New Terminal." That will open the command line that interact with your computer. See the screenshot below:
- For Windows users, to execute or run the program in the command line, run this command: "python My_program", and for Mac users, run this command: "python3 My_program.txt"
Results:
This screenshot, shows the output of 7. The key to the above steps, aimed to help you get started with Visual Studio Code, and also to make you understand that a Python program is nothing more than a text file. You write and execute it using the Python command.
The Steps to Create and Run A Python program, Pt2
Again, The key to the above steps in Pt1, aimed to help you get started with Visual Studio Code, and also to make you understand that a Python program is nothing more than a text file. You write and execute it using the Python command.
Now, this part of the tutorial will show you an excellent way to execute Python programs by using a "Run button." Currently, there is no run button here because we need to install a python extension. Below are the steps to create and run the python program more efficiently.
Step1: Getting Started with installing Python Extensions
- Start by clicking on the left side of the primary sidebar.
- Select the four-block icon. Here, you will search for the extension suitable for executing python commands. See the screenshot below:
Step2: To search for the Python extensions:
- Type Python in the search window, and select the first extension, "Python IntelliSense(Pylance), Linting…."
- Then press "Install" if not already installed, It will take a couple of seconds to finish the installation.
Step3: To Activate the ""Run button":
- To activate the “Run button,” Return to the file explorer icon to access your file "My_program.txt".
- Right-click on the file name and select the "Rename" option. Rename your file to "My_program.py."
- Now, you can see the “python Run Button” in the top right corner of the IDE; see the screenshot below:
- The run button will only appear when there is a dot py extension.
- Hence, all python programs must have a dot py extension.
- Python will continually search for the
.py
extension before executing the program.
Step4: To Select a Python Interpreter:
- To select a Python Interpreter: Go to your menu bar.
- Select the "View" option followed by the "Command Palette" option. See the screenshot below:
- Select Python Interpreter,
- Select Python 3.10. See the screenshot below:
- Now, the bottom right corner of the IDE displays the current selected interpreter.
- If you want to change it, click on the version shown, and this will take you to point (4) of step4.
Results
- Now, you are ready to run the python program.
- So, click the Run button to execute the program, the ouput will be displayed on the Python command line. See the screenshot below:
Conclusion
As you have seen, there are two ways to run Python programs.
- Either use the Python command we did with py -3 and then mention the file’s name. Or you use the easier way, which is by using the Run button.
- To use the Run button, you need to name your files with dot py at the end, and that’s the best practice.
- IDE extensions also will work better if you have your file names with dot py.