Since it is one of the best programming languages ??to learn and use, it should come as no surprise that millions of new programmers are turning their attention to learning Python. It offers a low entry threshold, with Python support available on all major operating systems, allowing you to build projects from websites to board games (etc.).
Python is usually preinstalled on macOS and Linux, but there are a few additional hoops that Windows users will need to go through before they can start using Python in 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
Since Python is not preinstalled with Windows, you need to install it first. There are two versions of Python available, Python 3 and Python 2. For compatibility reasons, you may need to install and use Python 2 with your old Python software.
However, support for the latest version of Python 2 (Python 2.7) is ending in 2020, so for now it is probably best to stick with installing Python 3.
- To get started with Python, you will need to go to the Python website and download the latest installer. As mentioned, we recommend that you download the latest stable version of Python 3.
- Once downloaded, run the Python installer. You will be presented with a very easy-to-use installer menu with options to run the installer with automatic settings or configure it before installation.
However, before choosing any of the options, check the “Add Python to PATH” checkbox at the bottom to add Python to your PATH. This will make it easier to launch Python from the command line or PowerShell by simply typing python rather than the full path.
- When you’re ready to begin installing Python on Windows, select Install Now to install Python with the default settings, or Customize Installation to make changes before starting the installation.
- If you choose customization, you will be presented with several additional menus. The Advanced Features menu shows the various features that will be installed with Python, including Python documentation. Components with the checkboxes enabled will be installed, so click any of them to prevent them from installing, then click Next to continue.
- In the Advanced Options menu, you can customize how Python is installed. You can leave these settings for the most part, although you can click to check the Install for all users box if you have multiple user accounts on your computer.
You can also choose a custom install point for your Python installation in the “Configure install location” box. Click Install to start the installation from now on.
- If the installation was successful, you should see the final “Installation was successful†screen. If you’re shown an option, click the Disable Path Length Limiting button. This is to circumvent the 260 character limit for folder and file path lengths. Otherwise, click the Close button to finish.
How to run Python projects on Windows
Once Python is installed, you can use it to run existing Python software or start developing your own Python projects. You will need a Python IDE to start coding your own Python projects, such as the pre-included IDLE, which you can launch from the Windows Start menu.
To run the Python code itself, you need to use the Python interpreter. It is software that converts Python code and executes it accordingly on your Windows PC. You will need to open a Command Prompt or PowerShell window to be able to use the interpreter.
– /
- To open a PowerShell window, right-click the Windows Start menu and click Windows PowerShell to start.
- If you added Python to your Windows PATH during installation, you can start the interpreter by typing python or py in a terminal window. If you haven’t, you will need to use the full path to your Python interpreter to be able to run it.
- The interpreter allows you to type Python code and run it manually. For example, print (“Hello World”) will return Hello World as printed by the interpreter.
- This is great for testing and learning Python, but the Python interpreter is also used to run longer files of Python code as well as compiled Python software.
You can do this by typing python filename.py or py filename.py in a PowerShell window, replacing filename.py with your Python file. Use the filename.pyc equivalent to run compiled Python files with the PYC file extension.
- If you are unsure about something using the Python interpreter, enter help () to load the help utility. You can find a list of available Python modules by typing modules, themes by typing topics, keywords by typing keywords, and symbols by typing symbols. When finished, enter quit to exit the help utility and return to the interpreter.
- To exit the Python interpreter and return to the standard PowerShell window, type exit () and press Enter.
Install additional Python modules
Many Python projects are built to take advantage of other modules — common software that other projects can use to save time rather than reinvent the wheel. You can find and install additional modules using PIP, the Python Package Index.
Before you can start, you need to have Python PIP installed, although if you have installed Python 3.4 or newer it should be preinstalled unless you removed this option during Python preconfiguration.
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 package name of the module you can install. You can search for packages to install using the search tool on the PIP website
Python Next Steps
As we’ve shown here, you don’t need to switch to Linux or Mac to master this beginner-friendly programming language. Once you learn how to use Python on Windows, you can start thinking about how to use it to your hobbies and interests.
If you want to turn your Windows installation into a better platform for testing your code, you might consider switching from PowerShell and installing Windows Terminal instead. Do you have your own Windows programming tips? Please leave them below.
–