Build websites, games and lots more
As one of the best programming languages to learn and use, it’s no wonder that millions of new coders turn their attention to learning how to use Python. It offers a low barrier of entry, with support for Python available on all major operating systems, allowing you to build projects from websites to desktop games (and more).
Python is usually found pre-installed on macOS and Linux, but there are a few additional hoops Windows users will need to jump through before they can start using Python for their projects. Here’s what you need to know if you want to learn how to use Python on Windows.
How to Install Python on Windows
As Python doesn’t come pre-installed with Windows, you’ll first need to install it. There are two available versions of Python—Python 3 and Python 2. For compatibility reasons, you might be required to install and use Python 2 with older Python software.
Support for the last release of Python 2 (Python 2.7) ends in 2020, however, so at this stage, it’s probably best to stick with installing Python 3.
- To get started with Python, you’ll need to head to the Python website and download the installer for the latest release. As mentioned, we recommend you download the latest Python 3 Stable release.
- Once downloaded, run the Python installer. You’ll be presented with a very easy-to-use installer menu, with options to run the installer with automatic settings or customize it prior to installation.
Before selecting either option, however, press the Add Python to PATH checkbox at the bottom to add Python to your PATH variable. This will make it easier to run Python from a command line or PowerShell by simply typing python, rather than the full path.
- When you’re ready to begin installing Python on Windows, click the Install Now option to install Python using the default settings, or Customize Installation to make changes before the installation begins.
- If you choose to customize your installation, you’ll be presented with a few additional menus. The Optional Features menu shows various features that will be installed with Python, including the Python documentation. Features with enabled checkboxes will be installed, so click on any of these to prevent them from being installed, then press Next to continue.
- In the Advanced Options menu, you’ll be able to customize how Python will be installed. You can leave these settings for the most part, although you may wish to click to enable the Install for all users checkbox if your PC has multiple user accounts.
You can also choose a custom installation point for your Python installation under the Customize Install Location box. Click Install to begin the installation at this point.
- If the installation was successful, you should see the final Install was successful screen. If the option is shown to you, press the Disable path length limit button. This is to bypass the 260-character limit for folder and file path lengths. Otherwise, press the Close button to finish.
How to Run Python Projects on Windows
Once Python is installed, you’ll be free to use it to run existing Python software or begin developing your own Python projects. You’ll need a Python IDE to be able to begin coding your own Python projects, such as the pre-included IDLE, which you can run from the Windows Start menu.
To run Python code itself, you need to use the Python interpreter. This is the software that converts Python code and executes it appropriately on your Windows PC. You’ll need to open a command line or PowerShell window to be able to use the interpreter.
- To open a PowerShell window, right-click the Windows Start menu and press Windows PowerShell to begin.
- If you added Python to your Windows PATH variable during installation, you should be able to launch the interpreter by typing python or py at the terminal window. If you didn’t, you’ll need to use the full path to your Python interpreter to be able to launch it.
- The interpreter allows you to type Python code and run it manually. For instance, print(“Hello World”) will return Hello World, printed by the interpreter.
- This is great for testing and learning Python, but the Python interpreter is also used to run longer files with Python code, as well as compiled Python software.
You can do this by typing python filename.py or py filename.py at a PowerShell window, replacing filename.py with your Python file. Use an equivalent to filename.pyc to run compiled Python files with the PYC file extension.
- If you’re unsure about anything while you’re using the Python interpreter, type help() to load the help utility. You can find a list of available Python modules by typing modules, topics by typing topics, keywords by typing keywords, and symbols by typing symbols. Once you’re finished, type quit to exit the help utility and return to the interpreter.
- To exit the Python interpreter and return to a standard PowerShell window, type exit() and press enter.
Installing Additional Python Modules
Many Python projects are built to take advantage of other modules—shared software that other projects can use to save time, rather than “reinventing the wheel.” You can find and install additional modules using PIP, the Python Package Index.
You’ll need to install Python PIP first before you can begin, although if you’ve installed Python 3.4 or later, it should come pre-installed unless you removed the option during your Python pre-installation configuration.
You can use PIP to install new modules by opening a PowerShell window and typing pip install package-name or python -m pip install package-name, replacing package-name with the name of a module package you can install. You can search for packages to install by using the search tool at the PIP website.
Next Python Steps
As we’ve shown here, you don’t need to switch to Linux or a Mac to be able to pick up this beginner-friendly programming language. Once you know how to use Python on Windows, you can start looking at how to use it for your hobbies and interests.
If you want to turn your Windows installation into a better platform to test out your code, you might think about switching from the PowerShell and installing the Windows Terminal instead. Do you have your own Windows coding tips to share? Please leave them below.