How to Open and View Python Files on Windows 11

If you’ve ever downloaded or received a file ending in .py, you’re dealing with a Python script — a text file that contains Python code. But what if you just want to open it, view the contents, or even run it on your Windows 11 PC?

Unlike Word or Excel documents, .py files don’t automatically open with an easy-to-recognize app. So, if you’re double-clicking and nothing happens (or worse, Windows asks you to pick an app), don’t worry — it’s completely normal.

In this guide, we’ll show you exactly how to open, view, and even execute Python .py files on Windows 11 using built-in apps and popular tools like Visual Studio Code, Notepad++, and IDLE.

What Is a .PY File?

A .py file is a Python source code file. It contains lines of text written in the Python programming language, which is used for tasks like automation, data analysis, web development, and AI.

Essentially, a .py file is just a plain text file that tells Python what to do — but you need the right editor or interpreter to open or run it properly.

Common examples include:

  • main.py — the main script of a project
  • app.py — used in Flask or Django web apps
  • setup.py — for Python package installation

What You’ll Need

Before you open or view .py files, make sure you have:

  • A Windows 11 PC or laptop
  • A text editor (like Notepad, Notepad++, or Visual Studio Code)
  • (Optional) Python installed — if you want to run the file, not just view it

You can check if Python is already installed by opening Command Prompt and typing:

python --version

If it returns a version number (like Python 3.12.2), you’re good to go. If not, you’ll need to install Python (we’ll cover that below).

Method 1: Use Visual Studio Code (Recommended)

Visual Studio Code (VS Code) is one of the best tools to open, read, and edit Python files. It highlights syntax, provides auto-completion, and can even execute Python scripts directly.

  1. Go to https://code.visualstudio.com and download VS Code for Windows.
  2. Install it by following the on-screen instructions.
  3. Once installed, right-click on your .py file and select Open with → Visual Studio Code.
  4. The code will appear with colored syntax highlighting.
  5. To run the script, install the Python extension from the Extensions tab (Ctrl + Shift + X → search “Python” → install).

Now you can open, edit, and even execute .py files directly inside VS Code.

Method 2: Use Notepad or Notepad++

If you only need to view or make small edits to the .py file (without running it), Notepad or Notepad++ is a quick option.

Using Notepad:

  1. Right-click the .py file → select Open with → Notepad.
  2. You’ll see plain text code, but without color highlighting.
  3. Great for simple edits, but not ideal for large projects.

Using Notepad++ (better option):

  1. Download Notepad++ from https://notepad-plus-plus.org.
  2. Install it and open your .py file.
  3. Notepad++ automatically highlights Python syntax, making the code more readable.
  4. You can also run basic macros or search across multiple files if needed.

Method 3: Use IDLE (Built-In Python Editor)

If Python is installed on your PC, it includes a built-in editor called IDLE. It’s simple but functional for viewing and running Python files.

  1. Right-click your .py file → select Open with → Choose another app.
  2. Click More apps → Look for another app on this PC.
  3. Navigate to your Python installation folder (usually C:\Users\<YourName>\AppData\Local\Programs\Python\Python3x\).
  4. Select IDLE (Python x.x) and click Open.
  5. Your .py file opens in IDLE’s editor, where you can view and run it (F5 to execute).

Method 4: Use Command Prompt to Run the File

If you want to execute the code instead of just viewing it, you can do so directly from Command Prompt or Windows Terminal.

  1. Make sure Python is installed.
  2. Press Windows + S and search for cmd → open Command Prompt.
  3. Navigate to the folder containing your .py file: cd path\to\your\file
  4. Type: python filename.py
  5. Hit Enter, and Python will run the script.

If you get an error saying “python not recognized,” you need to add Python to PATH or reinstall Python with that option enabled.

Method 5: Use Online Python Viewers or IDEs

If you don’t want to install anything, you can view or run .py files online using a browser-based editor.

Some great web-based options:

Just upload your .py file and you can view or execute it directly from your browser.

Wrapping Up

And there you have it — several easy ways to open and view Python (.py) files on Windows 11.

If you just want to peek at the code, tools like Notepad++ or VS Code are perfect. But if you want to actually run the code, make sure Python is installed and set up properly.

Our recommendation? Go with Visual Studio Code. It gives you color syntax, intelligent code completion, built-in terminal, and the flexibility to run scripts — all from one window.

So whether you’re a beginner exploring your first .py file or a developer setting up your coding environment, Windows 11 gives you plenty of options to get started quickly and confidently.

Posted by Arpita

With a background in Computer Science, she is passionate about sharing practical programming tips and tech know-how. From writing clean code to solving everyday tech problems, she breaks down complex topics into approachable guides that help others learn and grow.

X