How to Install and Run Python on Windows

ยท

6 min read

Python is a popular and versatile programming language that can be used for various purposes, such as web development, data analysis, machine learning, automation, and more. Python is also easy to read and write, and has a large and active community of developers and enthusiasts.

If you want to learn Python or use it for your projects, you need to install it on your computer first. In this article, I will show you how to install and run Python on Windows in a few simple steps.

Step 1: Download the Python Installer

The first thing you need to do is to download the Python installer from the official website: python.org/downloads

You will see a big banner at the top indicating the latest version of Python. As of this writing, the latest version is Python 3.10.1. You should always download the latest version of Python, unless you have a specific reason to use an older one.

Click on the "Download Python 3.10.1" button to start the download. You will get a file named something like python-3.10.1-amd64.exe, depending on your system architecture (32-bit or 64-bit).

Step 2: Run the Python Installer

Once you have downloaded the installer, open the .exe file by double-clicking it to launch the Python installer.

There are two important things you need to do here:

  • Check the box that says "Add Python 3.10 to PATH". This will allow you to run Python from any directory in your system, without having to specify the full path to the executable file.

  • Click on the "Customize installation" button. This will let you choose which features and components you want to install with Python.

Step 3: Customize the Python Installation

After clicking on the "Customize installation" button.

Here, you can select which optional features you want to install with Python. The default selection is usually fine for most users, but you can change it according to your preferences and needs.

Some of the optional features are:

  • Documentation: This will install the official Python documentation on your computer, which you can access offline or online.

  • pip: This is a tool that allows you to install and manage third-party packages and libraries for Python. You should always install pip, as it is very useful and widely used.

  • IDLE: This is a simple integrated development environment (IDE) for Python, which lets you write and run Python code interactively. You can use IDLE if you don't have any other IDE or code editor installed.

  • Python test suite: This will install a collection of tests that can be used to check the functionality and compatibility of your Python installation.

  • py launcher: This is a utility that allows you to launch different versions of Python from the command line, if you have more than one installed.

After selecting the optional features, click on "Next" to proceed.

Step 4: Choose the Installation Location

The next window will let you choose where you want to install Python on your computer. The default location is usually C:\Users\<username>\AppData\Local\Programs\Python\Python310, where <username> is your Windows username.

You can change this location if you want, but make sure you have enough space on your drive and that you remember where you installed Python.

You can also choose whether you want to install Python for all users of your computer or only for yourself. If you are not sure, choose "Install for all users".

Click on "Install" to start the installation process.

Step 5: Wait for the Installation to Complete

The installation process may take a few minutes, depending on your system speed and configuration. You will see a progress bar indicating how much time is left.

You can click on "Disable path length limit" if you want to avoid potential issues with long file paths in Windows. This is optional but recommended.

You can also click on "Close" to exit the installer.

Congratulations! You have successfully installed Python on your Windows computer!

Step 6: Verify Your Python Installation

To verify that your Python installation is working properly, you need to open a command-line application, such as PowerShell, Command Prompt, or Windows Terminal.

To open PowerShell, press the Win key, type PowerShell and press Enter. Alternatively, you can right-click the Start button and select "Windows PowerShell" or "Windows PowerShell (Admin)".

To open Command Prompt, press the Win key, type cmd, and press Enter. Alternatively, you can right-click the Start button and select "Command Prompt" or "Command Prompt (Admin)".

To open Windows Terminal, press the Win key, type terminal, and press Enter. Alternatively, you can right-click the Start button and select "Windows Terminal" or "Windows Terminal (Admin)".

Once you have opened a command-line application, type the following command and press Enter:

python --version

You should see something like this:

Python 3.10.1

This means that Python is installed and added to your system path. You can also check the location of your Python executable by typing the following command and pressing Enter:

where python

You should see something like this:

C:\Users\<username>\AppData\Local\Programs\Python\Python310\python.exe

This is the path to your Python executable file. You can use this path to run Python from any directory in your system, or you can just type python if you have added it to your system path.

Step 7: Run Your First Python Program

To run your first Python program, you need to create a text file with a .py extension that contains some Python code. For example, you can create a file named hello.py with the following content:

print("Hello, world!")

This is a simple Python program that prints a message to the standard output.

To run this program, you need to navigate to the directory where you saved the file using the command-line application. For example, if you saved the file on your desktop, you can type the following command and press Enter:

cd C:\Users\<username>\Desktop

where <username> is your Windows username.

Then, you can run the program by typing the following command and pressing Enter:

python hello.py

You should see something like this:

Hello, world!

This means that your Python program ran successfully!

You can also run Python interactively by typing python without any arguments and pressing Enter. This will open a Python shell where you can type and execute Python commands directly. For example:

Python 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> print("Hello, world!")

To exit the Python shell, you can type exit() or press Ctrl+Z followed by Enter.

You are now ready to start learning and using Python for your projects!

If you want to learn more about Python installation and setup on Windows or other operating systems, you can check out these resources:

I hope you found this article helpful and informative. Happy coding! ๐Ÿ˜Š

Source:

ย