Installing Python on Windows
What is a Programming Language?
A programming language is a formal system of communication that allows humans to instruct computers to perform specific tasks. It consists of a set of rules, syntax, and vocabulary that define how to write code, which the computer can then interpret and execute. Programming languages enable developers to create software applications, control hardware, process data, and automate tasks.
What is Python?
Python is a high-level, general-purpose programming language that has gained immense popularity due to its simplicity, readability, and extensive library support. Developed in the late 1980s by Guido van Rossum, Python was designed to be easy to learn and use while providing the power needed for complex applications. It supports multiple programming paradigms, including procedural, object-oriented, and functional programming, making it versatile and adaptable to various use cases.
Installing Python
1. Download Python
Download the installer for the version you have chosen from https://www.python.org/downloads/windows/
Best Practice: Whenever possible, choose the latest version of Python.
As a Python programmer, you'll frequently use packages in your projects. A package is a reusable collection of code designed to handle tasks ranging from simple to complex (e.g., Django, Pandas, Numpy, etc.). It's important to note that packages often require specific Python versions to function correctly. To avoid compatibility issues, always check the package's documentation to ensure it supports the Python version you're using.
Lessons Learned: Ensure that the Python version in your local environment matches the one used in production.
The code you are running on your local computer will eventually live in a remote server. Be aware that some cloud service providers may not support the latest Python version, which can potentially break your production code. In the worst case, you might need to use outdated versions of your dependencies.
I encountered this challenge when I first deployed my application on shared web hosting. To avoid similar issues, I recommend using dedicated web hosting where you have complete control over your Python installation.
2. Run the Installer.
The “Add python.exe to PATH” checkbox will add the Python executable to the PATH environment variable. This allows you to use the python
command from any shell, such as Command Prompt or Windows PowerShell.
The PATH is a list of directories that your operating system searches for executable files when you run a command from the terminal. To see your PATH environment variable, type in environment
in the Windows search bar and press Enter
. In the System Properties dialog box that appears, click on the Environment Variables button. In the subsequent Environment Variables dialog, you will see the Path variable listed.
If you have added a Python executable to PATH, the command execution process works as follows:
- When you type `python` in the terminal and press `Enter`, the operating system starts by checking the current directory to see if there is an executable named python.exe.
- If it doesn't find python.exe in the current directory, it moves on to check the directories listed in the PATH variable, one by one, in the order they appear.
- As soon as it finds a python.exe in one of those directories, it will run that version of Python.
Lessons Learned: I do not recommend adding a Python executable to PATH.
If you have multiple versions of Python installed and all their directories are included in the PATH, the first one listed in PATH will be executed when you type python
in the terminal. For example, if Python 3.9 is listed before Python 3.10 and 3.11 in the PATH, Python 3.9 will run when you use the python
command in the terminal.
Best Practice: Use py
in the terminal instead of python
on Windows.
The py
command is the Python launcher for Windows, introduced in Python 3.3. It automatically detects the installed Python versions on your machine and delegates to the latest version by default. You can also specify a particular version to use, such as py -3.11
.
3. Verify that Python is installed.
Type the following command in the terminal:
1 |
|
This command launches the Python interpreter in interactive mode. This means the terminal switches from its default shell to a Python prompt, where you can enter and execute Python commands interactively. The >>>
prompt indicates that you're now in Python's interactive mode.
If you see something below, it means Python is installed on your computer:
1 2 3 |
|
If you type python
and the Microsoft Store opens, it means that python.exe was not added to the PATH environment variable.
To exit the Python interpreter and return to the terminal's regular shell, use the command below:
1 |
|