sodcalculator

10 Tech How-To

How to Use Python on Windows: A Step-by-Step Guide

Guide 10-48562 · Updated · Step by step

This guide walks you through installing Python on Windows, writing your first script, and running it from the command line. You’ll learn the essential steps to get a working Python environment, including how to handle common setup issues and avoid typical mistakes.

What You’ll Need

  • A Windows PC (Windows 10 or 11 recommended)
  • Internet connection to download the installer
  • Administrator rights on your PC (to install software)

Step-by-Step

  1. Download the Python installer. Open your web browser and go to the official Python website at python.org. Click the “Downloads” menu and choose the latest stable version for Windows (e.g., Python 3.12.x). The site usually detects your OS and shows a download button for Windows.
  2. Run the installer. Once the .exe file is downloaded, double-click it. Important: On the first screen, check the box that says “Add Python to PATH” at the bottom. This step is crucial—it lets you run Python from the Command Prompt. Then click “Install Now.” The installer will copy files and may ask for permission; click “Yes” if prompted.
  3. Verify the installation. After installation finishes, open the Command Prompt. Press Win + R, type cmd, and press Enter. Type python --version and press Enter. You should see something like Python 3.12.2. If you see an error, the PATH wasn’t set correctly—see Troubleshooting below.
  4. Open the Python interpreter (optional). In the same Command Prompt, type python and press Enter. You’ll see the Python prompt (>>>). Try typing print("Hello, World!") and press Enter. It should print the message. To exit, type exit() and press Enter.
  5. Write your first script. Open a text editor like Notepad (or better, a code editor like VS Code or Notepad++). Type the following line: print("Hello from Python!"). Save the file with a .py extension, for example hello.py. Make sure to choose “All Files” as the file type in Notepad to avoid saving it as .txt.
  6. Run the script. In the Command Prompt, navigate to the folder where you saved the script. Use the cd command, e.g., cd C:\Users\YourName\Desktop. Then type python hello.py and press Enter. You should see Hello from Python! printed.
  7. Install packages (optional). To use third-party libraries, use pip. For example, to install the requests library, type pip install requests in the Command Prompt. You can use pip list to see installed packages.
  8. Use an IDE (optional but recommended). For larger projects, install a proper IDE like PyCharm Community Edition or Visual Studio Code with the Python extension. These provide syntax highlighting, debugging, and easier project management.

Common Mistakes

  • Forgetting to check “Add Python to PATH” during installation. This is the most common mistake, leading to “Python is not recognized” errors.
  • Running the wrong command. On some systems, you might need to use py instead of python (e.g., py --version). This is because the Windows Store version of Python may alias python.
  • Saving a script with the wrong extension. Notepad often saves as .txt unless you specify. Always check the file name ends with .py.
  • Mixing Python 2 and Python 3. If you have both installed, python might point to Python 2. Use python3 or py -3 to force Python 3.
  • Not using a virtual environment. For projects, installing packages globally can lead to version conflicts. Use python -m venv myenv to create a virtual environment.

Tips

  • Use the py launcher if you have multiple Python versions. It lets you specify the version like py -3.11.
  • Keep your Python updated. New versions come with performance improvements and bug fixes.
  • Learn to use pip efficiently. You can install multiple packages at once: pip install numpy pandas matplotlib.
  • Set up a code editor with auto-save and linting to catch errors early.
  • Explore the official Python documentation—it’s comprehensive and beginner-friendly.

Troubleshooting

“Python is not recognized as an internal or external command”

This means Python is not in your PATH. To fix it, you can reinstall Python and check the “Add to PATH” box. Alternatively, manually add Python to PATH: go to System Properties (right-click This PC → Properties → Advanced system settings → Environment Variables), find the Path variable, and add the Python installation directory (e.g., C:\Python312) and the Scripts subfolder (C:\Python312\Scripts).

Installer fails to start

If the installer doesn’t run, right-click the downloaded file and select “Run as administrator.” If it still fails, download the installer again—it might be corrupted.

Python opens the Microsoft Store instead of running

This happens if you have the Windows Store alias enabled. Disable it by going to Settings → Apps → Advanced app settings → App execution aliases, and turn off the Python aliases. Or, use py instead of python.

Script runs but closes immediately

If you double-click a .py file and the console window closes instantly, the script finished. To see the output, add input() at the end of your script to pause, or run it from the Command Prompt.

pip not found

If pip is not recognized, ensure you have Python 3.4+ (which includes pip). If it’s still missing, run python -m ensurepip --upgrade.

Frequently Asked Questions

Q: Do I need to install Python from the Microsoft Store?

A: Not necessarily. The Store version is fine for beginners, but the official installer from python.org gives you more control and includes pip by default.

Q: What’s the difference between Python 2 and Python 3?

A: Python 2 is outdated and no longer maintained. Python 3 is the current standard. Always install Python 3.

Q: Can I use Python on Windows without installing anything?

A: You can use online interpreters like Replit, but for local development, you need to install Python.

Q: How do I update Python to a newer version?

A: Download the latest installer from python.org and run it. It will install alongside the old version, or you can uninstall the old one first.

Q: Why do I get a syntax error when I run a script?

A: Check for missing colons, parentheses, or indentation issues. Python uses indentation to define blocks, so be consistent with spaces or tabs.

Q: How do I uninstall Python completely?

A: Go to Settings → Apps, find Python, and uninstall. Also remove any leftover Python folders in C:\Users\YourName\AppData\Local\Programs\Python if needed.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →