
Python is a high-level general-purpose programming language known for its simplicity, readability, and versatility. Python is used in web development, data science, artificial intelligence, and automation tasks. Python works with PIP, a package installer for managing external libraries and dependencies required in applications depending on your project needs.
This article explains how to install Python and Pip on Windows. You will install Python and manage multiple versions using graphical and terminal-based methods. In addition, you will create isolated development virtual environments to install specific libraries with Pip depending on your project needs.
Before you begin, you need to:
You can install Python on Windows through multiple methods, including graphical and CLI steps. You can use the Windows store on desktop workstations, the Chocolatey package manager, or download the latest .exe Python package for Windows. Follow the steps below to install Python on Windows using any of the supported methods.
Microsoft Store is the default source for installing Python on Windows desktop workstations. Running python in a Powershell window opens the store to install Python. Follow the steps below to install Python using the Microsoft Store.
Open the Windows start menu, search for Microsoft Store and click Open to launch the store.
Enter python in the search bar and press ENTER.
Select your desired Python version published by the Python Software Foundation.
Click Get to download and install the Python.
Verify that the installation is successful.
Open the Windows start menu, search for Command Prompt and click Open to launch a new terminal window.
Verify the installed Python version on your Windows workstation.
Your output should be similar to the one below:
You can install multiple Python versions on Windows, allowing you to run different projects on your workstation. Multiple Python versions enable you to work on different projects that require specific Python versions. You can install multiple Python versions with all supported methods, including Chocolatey, Windows Store, or the Python installer package. Follow the steps below to install and manage multiple Python versions using Chocolatey on your Windows workstation.
Run Windows PowerShell as an administrator.
Install Python 3.12 (if it's not already installed).
Install additional versions by changing the version suffix in the package name. For example, install Python 3.11.
Repeat the above installation steps for every version you'd like to install on your Windows workstation.
Windows includes the Python Launcher (py) application, which allows you to manage and invoke multiple installed Python versions from the command line. Managing Python versions is useful when working with multiple projects that require different Python versions.
Open a new Windows PowerShell session.
List all installed Python versions.
Your output should be similar to the one below:
Run a specific Python version, such as 3.13, using the py launcher to open the Python shell. Replace 3.13 with the target Python version you'd like to access.
Run a script with a specific Python version. For example, run the hello.py script with Python 3.12.
Check the active Python version.
Your output should be similar to the one below:
Open the py.ini file and change the Python defaults option to change the default version on Windows.
You can use Python on Windows after installing it using any supported method. Running Python programs and commands requires Windows PowerShell or an IDE such as IDLE or VSCode that supports the Python language. You can also run Python directly using the Windows Command Prompt or PowerShell. Follow the steps below to use Python on Windows.
Open the Windows Powershell.
Verify the active Python version.
Enter python to open the Python shell.
Print a Greetings from Vultr message using Python.
Output:
Exit the Python shell.
Create a test hello.py script to verify that Python has access to the system directories.
Execute the file using Python.
Python virtual environments allow you to manage dependencies for individual projects. This prevents version conflicts between packages required by different applications. Follow the steps below to install the virtualenv module, create and manage virtual environments using Python.
Check the default Python version.
Your output should be similar to the one below:
Install the virtualenv module using pip for the default Python version.
Specify a Python version, such as python3.12 to install the virtualenv module.
Create a new venv virtual environment using the default Python version. Replace venv with your desired virtual environment name.
Activate the venv virtual environment.
Verify that your terminal prompt changes to the venv virtual environment.
Use Pip to install a package such as requests in the virtual environment.
List all installed packages in the virtual environment.
Your output should be similar to the one below:
Deactivate the virtual environment.
Python's package manager, Pip, is typically included when you install Python through Chocolatey or the official installer. You may need to install or upgrade Pip manually when managing multiple Python versions. Follow the steps below to verify the installed Pip version and upgrade it on your Windows workstation.
Verify the installed Pip version.
Your output should be similar to the one below:
Upgrade Pip.
Verify the upgraded Pip version.
Your output should be similar to the one below:
You have installed Python and pip on Windows using terminal and graphical-based methods. You can use Python in existing applications, create virtual environments and set up new Python applications with compatible tools, including IDEs and the Windows PowerShell. Visit the Python documentation for more information and configuration options.
0 Comments
Be the first to comment and share your perspective with the community.