Python for Windows Installation Guide 2021: Step By Step Guide Provided. Included manually set Python Path, disable Python Path Length Limit, update and manage multiple Python versions.

Python for Windows Installation Guide: Step By Step Provided. Included manually set Python Path, disable Python Path Length Limit, update and manage multiple Python versions.
Photo by Chris Ried on Unsplash

Python!

You can use Python to do everything, from server to client web app, even mobile apps. I use Python to write a web scraper to get the cryptocurrency price. Also, the editor called ProperTree to edit my Hackintosh's config.plist is written in Python. You definitely can find a Python use case in your daily life.

This article will discuss the steps to check if Python is installed, the basic installation process, and several configurations, like adding Python to PATH, updating and managing different Python versions, and enabling long path settings.

How to check if Python is installed in Windows

  1. Call the Run by press Windows + R keys.
  2. Type "CMD" in the Open column and click the OK button to open CMD.
  3. Type "python --version" and press enter.

If CMD returns a message saying " 'python' is not recognized as an internal or external command, operable program or batch file.", which means Python is not installed or the PATH is not set.

The next step to confirm it, you can try to search Python this keyword in Windows Search. If the result returns a Python-related file or icon, that means Python is installed. You can refer to the "What and Why adding Python to PATH?" section to add the Python PATH.

How to Install Python?

  1. Download the Python installer from python.org
  2. Double click the Python installer to launch it. 
  3. Look at the bottom of the installer window, which has an Add Python to PATH checkbox in an unchecked state. Check it now.
  4. Click the Install Now button.
  5. Wait until the installation process is complete.
  6. Once the installation is complete, it may or may not show the option Disable path length limit. If the option is available, click it to disable the limit.
  7. Your Python installation had done.

What and Why adding Python to PATH?

Without Adding Python to PATH, we are unable to call Python to execute the command shortly.

Without adding Python to PATH:

when you type "python" in the command prompt, the command prompt will respond unable to recognize this command.

The command prompt only recognizes the command with full python.exe path or changes the command prompt directory to the folder containing python.exe.

If you skip or miss out the adding Python to PATH, you can add the Python.exe path by the following steps:

Go to User Variable: 

  1. Go to This PC.
  2. Inside This PC's window, right-click in any white space. 
  3. Click Properties.
  4. Click Advanced system settings.
  5. In the Advanced tab, click Environment Variables.
  6. In the User variables for xxx's section, select the Path variable and click the Edit button

Find the folder containing python.exe and the script folder. 

  1. Type "Python" in the Windows search bar.
  2. Select one of the Python-related apps, right-click and click Open file location. In my case, the file location contains Python-related shortcuts(not the actual file location)
  3. Select one of the shortcuts(IDLE or Python), right-click, and click Open file location.
  4. Copy the folder path, back to the User variables window, click the New button, and paste the folder path to the space provided
  5. Also, copy the Script folder path(in the same Python folder) and add it to the user variable
  6. Click the OK button to save all the configurations. 

After all the configurations above, the CMD should recognize the "python --version" command. 

Adding the Script folder path to the user variable enables the CMD to run the script(tools). The Script folder contains all the Python tools, like pip(Package installer).

How to Update Python?

For small point updates, for example, Python 3.9.1 to 3.9.2, you can update through the latest Python installer.

For major or minor updates, for example, Python 2 to Python 3 or Python 3.8 to 3.9, you will install every version on your computer. You will find out Python 2, Python 3, and Python 3.9 installed on your computer.

Yup, this is how it works.

You may confuse that so many python versions are installed on your computer. So, the Python launcher comes in to solve this issue

Python launcher will default check when you install the latest Python.

After installed, you can type and enter "py <your command>" in CMD. Python launcher will pick the latest Python to execute it. You also can enter "py -3.10 <command>" to indicate which Python version to interpret your command

By the way, you should use Python 3 instead of Python 2. Last year, the Python software foundation already dropped support for Python 2.  

Why Disable Path Length Limit?

This setting is inherited from the ancient Windows operating system. It's limit a path to 260 characters; over the limitation will cause the system prompt error.

To disable it, you can follow the steps below:

  1. Use Windows key + R to open Run
  2. Enter "regedit" and click the OK button. 
  3. In the Register Editor, you need to navigate to HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > Control > FileSystem
  4. Double click the LongPathsEnabled properties.
  5. Change the value from 0 to 1 and click the OK button.
  6. That's it. You can close all the windows now.

Final words

The Python installation is not complicated. It takes about a few minutes or a few seconds to complete it. If you miss out on the options while installing, you can follow the guide above to manually add the Python path and disable the path length limit. Additionally, if you have multiple Python versions, you can follow the guide above to manage it. Hopes you learn something from this article.

Extra:

Youtube video: Python for Windows安装教学(Mandarin)

Next Post Previous Post
No Comment
Add Comment
comment url