How to Install Python on Windows Using Chocolatey

Haris Bin Nasir Avatar

·

·

Setting up Python on a Windows machine is often a critical first step for developers working with the language. While there are several ways to install Python, one of the easiest methods involves using Chocolatey, a package manager for Windows. This guide will walk you through the process of installing Python on your Windows 10 or 11 system using Chocolatey, ensuring that you have the latest version up and running quickly.

If you prefer watching a video tutorial here is a link to that.

What is Chocolatey?

Chocolatey is a package manager for Windows, similar to what Homebrew is for macOS. It simplifies the process of installing, updating, and uninstalling software using command-line tools. By using Chocolatey, you avoid the need to manually download and configure Python installers, ensuring that the software installed is legitimate and up-to-date.

Benefits of Using Chocolatey:

  1. Package Management: Easily manage software installations across your system.
  2. Security: Chocolatey verifies packages to ensure they are safe to install.
  3. Ease of Use: Install and manage software through simple command-line commands.

Step 1: Install Chocolatey

Before installing Python, you need to install Chocolatey on your Windows system. This requires using PowerShell with administrative privileges.

Instructions:

  • pen PowerShell as Administrator:
    • Press Windows + S and type “PowerShell”.
    • Right-click on PowerShell and choose “Run as administrator”.
  • Set Execution Policy: To allow PowerShell scripts to run, you need to set the execution policy. Use the following command:
Set-ExecutionPolicy AllSigned

Press Enter, then type Y to confirm.

  • Install Chocolatey: Next, install Chocolatey by pasting the following command into PowerShell:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

This command will install Chocolatey on your system. Once the installation is complete, close PowerShell and reopen it as an administrator.

  • Verify Chocolatey Installation: To confirm that Chocolatey was installed successfully, type the following command:
choco --version  

If you see the version number displayed, Chocolatey is installed and ready to use.


Step 2: Install Python Using Chocolatey

With Chocolatey installed, you can now proceed to install Python. This method ensures that you’re getting a verified version of Python, making it safer and easier to manage.

Instructions:

  1. Check the Latest Version of Python: Before installing, you can visit the official Python website to verify the latest stable version. At the time of writing, the stable version is Python 3.12.
  2. Install Python with Chocolatey: To install the latest version of Python (3.12), enter the following command in PowerShell:bashCopy codechoco install python --version=3.12 Chocolatey will automatically download and install Python 3.12 on your system.
  3. Verify Python Installation: Once the installation is complete, you can verify it by typing:bashCopy codepython --version You should see the installed version of Python, confirming that everything has been set up correctly.

Step 3: Managing Python Versions with Chocolatey

One of the biggest advantages of using Chocolatey is how easy it makes managing multiple Python versions or uninstalling Python altogether.

Uninstall Python:

If you want to uninstall Python, you can do so with a single command:

choco uninstall python

This will remove the installed Python version from your system.

Install Other Versions of Python:

To install a different version of Python (such as Python 3.11), simply modify the version number in the installation command:

choco install python --version=3.11

This flexibility allows you to manage various versions of Python without needing to manually uninstall and reinstall them.


Advantages of Using Chocolatey for Python Installation

  1. Easy Updates: Chocolatey makes updating Python (and other software) seamless, with a simple command to update to the latest version.
  2. Security: All packages on Chocolatey are verified and approved by the community, ensuring that you are not installing potentially harmful software.
  3. Centralized Management: Chocolatey allows you to manage all software installations from a single place, reducing the overhead of managing installations individually.

Conclusion

Using Chocolatey to install and manage Python on your Windows machine simplifies the process and ensures that you have a secure and easily updatable Python environment. Whether you are setting up Python for the first time or managing multiple versions for different projects, Chocolatey offers an efficient, reliable solution. For more advanced Python setups and configurations, be sure to explore additional Chocolatey commands and options.

Happy Coding…!!!

Leave a Reply

Your email address will not be published. Required fields are marked *