Python Environment Setup Tutorial - Beginner's Guide
The steps that we are going to perform today are:
- install latest version of Python 3
- install Visual Studio Code
- install some Visual Studio Code themes
- create hello.py to test our install
Let’s the fun begin!
Unravel the magic of Python programming, where code comes alive in a whirl of blue and yellow! 🌐🐍💫
Installing Python 3
Depending on what operating system you are running, you may already have a version or two of Python installed. That’s ok. Some programs require a certain version of Python to be installed, so we are not going to touch what is already there and instead install the latest version for this course.
Head over to download python 3 and get the latest stable version for your operating system. At the time of this writing, it is Python 3.12.1. Anything over version 3.7 should work exactly the same for what we are going to be doing through this course, but I always err on the side of getting whatever the latest version that is available.
Once you have it downloaded, install it like you would any other application accepting all of the default prompts.
Installing Visual Studio Code (VSCode)
Once that is installed, we are going to install VSCode. It should give you the version for your operating system right off the bat, but just in case, make sure to check that you are getting the version you need for your operating system.
Once that is downloaded, install it just like any other application on your computer.
Enable The Python Extension
Now that we have the latest version of Python3 and VSCode installed, we are going to enable the Python extension for Visual Studio Code. Open the extensions tab at the side and in the search bar at the top type python.
It should be the first one and called Python. Select it and click the install button. I already have it installed so I have the uninstall option. You know when it is installed when you have the uninstall option as well.
Picking A Suitable Visual Studio Code Theme
Once we have it all up and running, it is time to add a little bit of customization. Again we are going to open the extensions tab on the side but this time we are going to search for theme. Alternatively, you can also go to the category of themes to get a complete listing. This presents you with a list of a lot of the themes available to use in VSCode. Go ahead and install a few of them to check out. I would not go overboard and install every theme that you can see as this can slow things down. Try to keep the number of installed themes to a minimum by uninstalling the ones that you do not use.
Creating Our First Python 3 Script
We are now ready to start creating our very own scripts. Before we do that, we have to decide where we want to save all of these files we will be creating. While this is completely up to you, I recommend creating a folder in your Documents folder. I am going to call mine Python Programming Essentials. For every module that I start, I will create a new sub folder to hold all of the scripts for that module.
So now I have a folder in my Documents folder called Module 1.
└── Module 1/
There are 2 ways to open this path in VSCode. The first way is to use the File menu and select Open. Then just navigate to the path and click Open.
The second way is the one that I use the most. If I have the folder open, then I can just drag it into the larger window in VSCode. This will automatically open the folder for us.
Regardless of the method that you used, once you have the path open, you can view it using the Explorer. You should see your folder name there. I am going to right click in the open area and select New File. I will call it hello_world.py. This will open the new file in the editor window. While we are not going to cover coding in this lesson, but I am going to provide a line of code to add to the file so we can test to make sure everything is running correctly.
You can copy this line of code and save the file from the File menu.
We can run the script by pressing the play button in the top right of the screen. This will open the terminal at the bottom of the screen. There should be some output that says Hello World!. The colors may be different as that is controlled by the theme that you chose earlier, but the text should be there.
Congratulations on making it to the end of the first lesson. You managed to get Python 3 installed, and VSCode along with a theme that you like. We created the folder structure of our course, and then created the first script to test that everything was running correctly. Let’s get up and take a stretch, get a drink of water, and then get ready to start creating our own programs in Python.