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
- 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. - Run the installer. Once the
.exefile 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. - Verify the installation. After installation finishes, open the Command Prompt. Press
Win + R, typecmd, and press Enter. Typepython --versionand press Enter. You should see something likePython 3.12.2. If you see an error, the PATH wasn’t set correctly—see Troubleshooting below. - Open the Python interpreter (optional). In the same Command Prompt, type
pythonand press Enter. You’ll see the Python prompt (>>>). Try typingprint("Hello, World!")and press Enter. It should print the message. To exit, typeexit()and press Enter. - 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.pyextension, for examplehello.py. Make sure to choose “All Files” as the file type in Notepad to avoid saving it as.txt. - Run the script. In the Command Prompt, navigate to the folder where you saved the script. Use the
cdcommand, e.g.,cd C:\Users\YourName\Desktop. Then typepython hello.pyand press Enter. You should seeHello from Python!printed. - Install packages (optional). To use third-party libraries, use
pip. For example, to install therequestslibrary, typepip install requestsin the Command Prompt. You can usepip listto see installed packages. - 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
pyinstead ofpython(e.g.,py --version). This is because the Windows Store version of Python may aliaspython. - Saving a script with the wrong extension. Notepad often saves as
.txtunless you specify. Always check the file name ends with.py. - Mixing Python 2 and Python 3. If you have both installed,
pythonmight point to Python 2. Usepython3orpy -3to force Python 3. - Not using a virtual environment. For projects, installing packages globally can lead to version conflicts. Use
python -m venv myenvto create a virtual environment.
Tips
- Use the
pylauncher if you have multiple Python versions. It lets you specify the version likepy -3.11. - Keep your Python updated. New versions come with performance improvements and bug fixes.
- Learn to use
pipefficiently. 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
- MacBook Charger Not Working? Fix It Now
- Fix Windows Cannot Be Installed to This Disk
- Zoom on iPhone & iPad: Host or Join a Meeting
- Fix iPhone SE 4 Unable to Activate: Step-by-Step
- Keep Important Emails From Getting Buried in iPhone Mail Categories
- How to Clear RAM on iPhone: Speed It Up