Whether you are new to programming or already fluid in a language or two, there are many sound reasons to learn Python. Just the fact that Python was ranked as the number one used programming language in 2017 should be enough to peak your interest. Python is known for its easy to follow syntax and efficiency when compared to other languages. To get started using Python, you first need to install it on your computer. The following is a step by step guide on how to install Python on Windows.
1. Download Python
Go to https://www.python.org/downloads/ in order to download the latest version of Python or to download subsequent versions of Python. Alternatively, you can go to https://www.python.org/downloads/windows/ where you can get the latest as well as older versions of python and chose which type of installer or file you want to download. For this tutorial I will be using the first link and clicking the “Download Python X.X.X” button near the top.
Once Python is done downloading run the installation software.
2. Install Python
Running the installation software will give you a window that says Install Python. At this window you want to make sure you check the box at the bottom that says “Add Python X.X to PATH”. Adding Python to PATH is similar to creating a desktop shortcut in that it will allow you to begin running a Python environment in your command prompt simply by typing “python” rather than always referring to the actual file location Python is in on your computer.
Next, you are going to click “Install Now” and the installation process will begin. After that has completed Python is fully installed and ready to be used.
If you didn’t have the “Add Python X.X to PATH” check box because you are using an older version of Python or you forgot to check it, don’t worry, go to step 3 to learn how to manually add Python to PATH. If you were able to add Python to PATH using the installation wizard you can move on to step 4.
3. Manually Adding Python to PATH
First, you are going to find where on your computer Python was installed and copy it’s folder location. In my case Python was installed in this file path on my computer: C:\Users\rtequ\AppData\Local\Programs\Python\Python36-32. (If you are unable to see the AppData folder that is because it is a hidden folder which you can make not hidden by hitting the windows key on your keyboard, typing folder options, going to the “View” tab, then clicking “Show hidden files, folders, and drives” under “Hidden files and folders” then clicking “OK”). Once you have located where Python is installed you are going to click on the windows button on the bottom left of your toolbar and type in “environment variables” and a selection should show up that says “Edit the system environment variables”. Click that and you will get a “System Properties” window where you will click “Environment Variables…” in the bottom right.
In the new window that pops up you are going to see multiple user and system variables your computer has already created. In the top half of the window under user variables you are going to look for a variables called “path”. If you already have a variable called “path” you are going to click “Edit…”
In the new window you want to click “New” and paste the location where Python is installed that we found earlier.
Then you are going to click “New” again and paste the same file location except this time add “Scripts\” to the end of that file location as you can see in the screenshot above right above the red box on the left. Then click “OK” to apply your path changes. If you don’t already have a variable called “path” you want to click “New…” to the left of “Edit…” and in the “Variable name:” box type “Path” and in the “Variable value:” box add the file location we got at the beginning of this step and the same file location plus “Scripts\” added to the end with the two paths separated by a semicolon (the full value I added to “Variable Value” is: C:\Users\rtequ\AppData\Local\Programs\Python\Python36-32\;C:\Users\rtequ\AppData\Local\Programs\Python\Python36-32\Scripts\)
Then, click “OK” and “OK” again to apply and exit your environment variables. From here on out you will be able to run Python in your command prompt by simply typing “python”, running scripts you created, and doing pip installs.
4. Running Python and Scripts
Open up command prompt and type “python” and you will move right into the Python coding environment.
From here you can begin coding in Python. If you want to run Python scripts that execute a pre-written set of code then all you have to do is open up command prompt and type in the location the script is held and the filename of the script. For example, I have my scripts located on an external hard drive and in a folder called “Python” which is located in another folder called “Programming”. So, in command prompt I would type the following:
Where I wrote “MyScript” you would type the whatever you named your script then hit enter and your script will begin to run in command prompt.