Installing Python
Greetings,
Note: this tutorial demonstrates installing an older version of Python; however, this walkthrough still applies to the current versions. In order to get started playing around with Python, you must first install it on your system. Here, I will walk you through those steps and any errors that might occur during the process. Let us go on over to Python.org:
As you can see above, you can install Python for Mac OS, Windows and other platforms. In this example, I will be installing on windows. Currently, as of the writing of this tutorial, the most recent version of Python you can get is version 3.8.3 and throughout this blog series we will use this version exclusively, at least until a newer implementation id rolled out. Python will work for either 64 or 32 bit Windows OS. However, 64bit Python will not work on 32bit Windows OS. Now, let us hover our cursor over the Downloads tab and download the python executable file for your OS:
In my case, my current Python installation will be replaced with the newest version. If you are installing Python for the first time, then your install prompt will read a bit differently from what is shown above; instead it will show you your default install path/location. Note: for first-timers, somewhere near the bottom of the install prompt you will see a checkbox, an option to add Python to your system environment variables. Make sure you check that box then proceed with the install:
At this point you can sit back, relax and wait until the installation finishes, unless you get an error during install (which I doubt if you followed along correctly so far). If the install went smoothly then congratulations! Now comes the moment of truth, testing to see if Python can run in command line. Run command line in admin mode; To do this, you must press both the windows icon and R keys on your keyboard at the same time; a window will open like the one in the example image below:
In the “open:” textbox type “cmd” then press control+shift+enter keys at the same time; this will allow you to run command line in administrator mode. You should now have this on your screen:
Notice the top bar on the screen where it says “Administrator: C:\\WINDOWS\system32\…”; This means you are now running Command line in administrator mode. This gives you all the privilege's to run commands on your system. Now that that’s out of the way, let us run the “python” command:
This command allows you to run the Python shell in cmd.exe; once you press enter you should see this in the output:
If you see this output, then congratulations! You have successfully installed Python 3.8 and this brings you to the end of the tutorial. However, if you are having problems running Python in cmd.exe, please proceed further down to the troubleshooting section.
Troubleshooting
So, you got an error when you either first tried to run Python in cmd.exe or when you tried to install a software package using pip (Python’s package installer). Don’t worry, this part of the tutorial will get you up ran running in no time. First, you are going to right click on the “This PC” on your desktop like so:
As you can see, this will bring up a list of options for that icon; Left click on the “Properties” option which will open the System screen:
The System screen has its own list of options; Device Manager, Remote Settings etc.; For now, you will left click on the “Advanced System Settings” option and this screen will open:
Now that you are in the System Properties applet, click on the button labeled “Environment Variables”: this will open the Environment Variables screen:
You see the highlighted area in the image above? That is the variable you want to edit; as you can see, it is located under the “User variables for [your username]” section. If I haven’t lost you yet, go ahead highlight the “Path” variable and then click on “Edit” button…
Ok, some background on what you see here; notice the two “C:\\…” paths already added to path variable. You more than likely do not see this on your “Edit environment variable” screen; it is because these are the paths you will need to add. Let’s hunt those down now. Open your file explorer then scroll down to your C: drive on the left of the screen…
Now open the Users ==> Username ==> AppData ==> Local => Programs => Python => Python38–32 folders. This is where Python is installed. Now click on the little drop down arrow in the address bar; this will highlight the path for you. once it’s highlighted, just right click the path and copy it:
Once you have done that, open notepad and paste the path into the file. You’ll just need a place to hold the paths until you reach the last few steps. Now go back to the file explorer screen where you just copied the path from and open the “Scripts” folder:
You are going to do the same thing you did in the previous step; click on the drop down arrow, highlight and copy the path. Then, paste the path into notepad. By the way, just in case something happens where your pc unexpectedly shuts down, go ahead and save that notepad file…just to be safe. Go back to the “Edit environment variable” screen you were in earlier then click on the “New” button:
Repeat the same step with the other path (Python). After you are done, click OK then click OK again; Now click Apply then OK once more. Reboot you system and open cmd.exe in admin mode. Type the python; if the Python shell starts, you are in good shape and now ready to go.
Whew! I am glad that’s over. I hope this tutorial was clear and useful to you. If there’s any thing you would like to suggest or just want to leave feedback, please feel free to comment and share. Head on over to my next tutorial where you will do some actual programming; Thank you and bye for now.