As one of the most beginner-friendly programming languages, it's no surprise that millions of aspiring programmers choose to learn Python. There are virtually no barriers preventing users from accessing and utilizing Python on major operating systems. This allows you to build everything from websites to PC games and much more.
Using Python on Windows: A Step-by-Step Guide
Getting Started with Python on Windows: A Comprehensive Guide
1. Installing Python on Windows.
2. Running Python Projects on Windows.
3. Installing Additional Python Modules.
1. Installing Python on Windows
Since Python isn't pre-installed on Windows, you'll need to install it. Currently, there are two Python versions available: Python 3 and Python 2. Depending on compatibility reasons, you may need to install and use Python 2 with older Python software.
However, support for Python 2 (Python 2.7) ended in 2020, so at this stage, it's probably best to install Python 3. Here's what you do:
Download the latest Python version here: Download Python
- Once the download process is complete, open the Python installer. You'll see a very user-friendly installation menu, with options to run the installer with automatic installation or customize it before installing and using Python.
However, before making a choice, check the Add Python to PATH option at the bottom of the window to add Python to your PATH environment variable. This will make it easier to open Python from the command line or PowerShell, simply by typing Python instead of the full path.
- Once you're ready to install and use Python on Windows, click on the Install Now option to install Python using the default settings, or Customize Installation to make changes before the installation process begins.
- If you choose to customize the installation, you'll be presented with additional menus. The Optional Features menu displays various features that will be installed along with Python, including Python documentation. Features with checkboxes will be installed, so you can uncheck any features you don't want to install, then press the Next button to proceed.
- In the Advanced Options menu, you'll be able to customize how Python is installed and used. You can skip most of these settings, although you may want to select Install for all users if your PC has multiple user accounts.
You can also choose a custom installation point for your Python installation under the Customize Install Location section. Click Install to begin the installation process.
- Upon successful installation, you'll see the Install was successful screen. If this option appears, click the Disable path length limit button. This is to bypass the 260-character limit for folder and file path lengths. Otherwise, click the Close button to complete the process.
2. Running Python Projects on Windows
Once Python is installed, you'll be able to comfortably use Python to run existing Python software or start developing your own Python projects. You'll need a Python IDE to start writing code for Python projects, such as the available IDLE that you can open from the Windows Start menu.
To run Python code, you'll need to use the Python interpreter. This is software that translates Python code and executes it correctly on your Windows computer. You'll need to open a command prompt or PowerShell window to use the interpreter.
- To open PowerShell, right-click on the Windows Start Menu and select Windows PowerShell to begin.
- If you've added Python to the PATH environment variable during installation, you'll be able to run the interpreter by entering python or py in the terminal window. Otherwise, you'll need to use the full path to the Python interpreter to launch it.
- The interpreter allows you to input Python code and run it manually. For example, print('Hello World') will output Hello World, executed by the interpreter.
- This is great for experimenting 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 entering python filename.py or py filename.py in the PowerShell window, replacing filename.py with your Python file. Use the equivalent of filename.pyc to run compiled Python files with the PYC file extension.
- If you're unsure about anything while using Python, simply type help() to load the help utility. You can find a list of available modules by typing modules, topics by typing topics, keywords by typing keywords, and symbols by typing symbols. Once done, type 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.
3. Installing Additional Python Modules
Many Python projects are built to leverage other modules - shared software that projects can use to save time rather than reinventing the wheel. You can find and install additional modules using PIP (Python Package Index).
You'll need to install Python PIP first before you can get started, although if you've installed Python 3.4 or newer, it comes pre-installed unless you opted out during Python's 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're installing. You can search for packages to install using the search tool on the PIP website.
With the detailed guide shared above, you don't need to switch to Linux or Mac machines to learn about this beginner-friendly programming language. Once you know how to use Python on Windows, you can learn how to use it to serve your hobbies and passions. For an objective comparison between Python and JavaScript, check out the article Comparing Python and JavaScript here.