Tutorials Logic, IN info@tutorialslogic.com

Install Python and Run Your First File

Python Setup

Getting started with Python means installing Python 3, checking the terminal command, creating a .py file, and running that file from a project folder.

Keep terminal commands in the terminal and Python code inside .py files. This one separation prevents many first-day setup mistakes.

A clean beginner setup uses a code editor, a small project folder, python -m pip for packages, and a virtual environment when a project needs third-party libraries.

Python Setup Steps

Getting started with Python means setting up Python on your computer, choosing a code editor, learning how to run Python programs, and understanding the basic project workflow. Once this setup is clear, the rest of Python learning becomes much easier.

In this lesson, you will learn how to install Python, check that it works, run code in different ways, create your first script, set up a simple project folder, and use tools like pip and virtual environments.

Install Python

Download Python from the official website: python.org/downloads. Use the latest stable Python 3 release unless your project specifically requires another version.

  • Open python.org/downloads.
  • Download the latest stable Python 3 installer for your operating system.
  • Run the installer.
  • On Windows, check Add Python to PATH before installing.
  • Finish the installation and open a new terminal.

Check Python Version

After installing Python, check the installed version from the terminal. This confirms that Python is available from the command line.

  • On Windows, python usually works.
  • On macOS and Linux, python3 may be required.
  • python -m pip is often safer than plain pip because it uses pip for the selected Python version.

Run the Version Command

Run the Version Command
python --version
# Example output:
# Python 3.12.4

# On some macOS/Linux systems:
python3 --version

# Check pip version:
pip --version
python -m pip --version

Code Editor

You can write Python code in any text editor, but a good editor makes learning faster by providing syntax highlighting, autocomplete, error hints, formatting, and terminal integration.

Editor Best For Notes
VS Code Most beginners and professionals Free, fast, excellent Python extension, built-in terminal
PyCharm Professional Python projects Full IDE with strong refactoring, debugging, and project tools
IDLE Absolute beginners Comes with Python, simple but limited
Thonny First-time programmers Simple interface and visual debugging support
Jupyter Notebook Data science and experiments Great for step-by-step exploration and charts

Interactive Mode

Interactive mode, also called the REPL, lets you type Python code and immediately see the result. It is useful for quick experiments, testing expressions, and learning syntax.

Use the REPL for small checks. For real programs, create a .py file so your code can be saved, edited, and reused.

Python REPL

Python REPL
python

>>> print("Hello, Python!")
Hello, Python!

>>> 10 + 5
15

>>> name = "Asha"
>>> print("Welcome", name)
Welcome Asha

>>> exit()

First Python File

A Python source file normally ends with the .py extension. For example, main.py, app.py, or hello.py.

  • print() displays output.
  • input() reads text typed by the user.
  • Variables store values like name, a, and b.
  • f-strings, such as f"Hello, {name}", insert values into strings.

First Python Script

First Python Script
# main.py
print("Hello, World!")

name = input("Enter your name: ")
print(f"Hello, {name}! Welcome to Python.")

a = 10
b = 3

print(f"{a} + {b} = {a + b}")
print(f"{a} - {b} = {a - b}")
print(f"{a} * {b} = {a * b}")
print(f"{a} / {b} = {a / b:.2f}")

Run the Script

Run the Script
python main.py

# Or:
python3 main.py

Python Indentation

Python uses indentation to define blocks of code. A block is a group of statements that belongs together, such as the body of an if statement, loop, function, or class.

Indentation Rules

Indentation Rules
score = 85

if score >= 50:
    print("Passed")
    print("Good job!")
else:
    print("Failed")
    print("Try again")

def greet(name):
    message = f"Hello, {name}"
    return message

Project Folder

As your code grows, keep files organized inside a project folder. Even a beginner project should have a clear structure.

File or Folder Purpose
main.py Main entry point of the program
helpers.py Reusable helper functions
requirements.txt List of third-party packages used by the project
README.md Project notes, setup steps, and usage instructions
tests/ Test files for checking program behavior

Python Getting Started Project Structure

Python Getting Started Project Structure
my_python_project/
|-- main.py
|-- helpers.py
|-- requirements.txt
|-- README.md
`-- tests/
    `-- test_main.py

pip Basics

pip is Python's package installer. It lets you install third-party libraries from PyPI, the Python Package Index.

Using pip

Using pip
# Install a package
python -m pip install requests

# Show installed packages
python -m pip list

# Save project dependencies
python -m pip freeze > requirements.txt

# Install dependencies from a file
python -m pip install -r requirements.txt

Virtual Environment

A virtual environment is an isolated Python workspace for one project. It prevents packages from different projects from interfering with each other.

Create and Activate a Virtual Environment

Create and Activate a Virtual Environment
# Create virtual environment
python -m venv .venv

# Activate on Windows PowerShell
.venv\Scripts\Activate.ps1

# Activate on Windows Command Prompt
.venv\Scripts\activate.bat

# Activate on macOS/Linux
source .venv/bin/activate

# Deactivate when done
deactivate

Setup Errors You Can Recognize

Symptom Likely Cause Fix
python is not recognized Python is not added to PATH Reinstall Python and select Add Python to PATH, or use the full Python path
pip installs to wrong Python Multiple Python versions installed Use python -m pip install package
Permission error while installing packages Installing globally without permission Use a virtual environment
IndentationError Missing or inconsistent indentation Use 4 spaces consistently
Script opens then closes quickly Double-clicking a script on Windows Run it from terminal with python file.py

Beginner Workflow

  • Create a project folder.
  • Open the folder in VS Code or your editor.
  • Create a virtual environment with python -m venv .venv.
  • Activate the virtual environment.
  • Create main.py.
  • Write a small program.
  • Run it with python main.py.
  • Install packages only when needed.
  • Save dependencies in requirements.txt.

First Project Check

Before moving to variables and data types, prove that your setup can run a saved file. Open the project folder in your editor, create main.py, run it from the terminal, and confirm the output appears where you expect.

If a command fails, check the exact command, the current folder, and the Python executable. Setup bugs usually come from PATH, a closed terminal session, or running the command from the wrong directory.

When packages enter the project, create a virtual environment first. Then use python -m pip so the package installs into the same Python installation that runs your code.

  • Run python --version or python3 --version in a new terminal.
  • Run python main.py from the folder that contains main.py.
  • Use python -m pip install package_name when installing a package.
  • Activate the virtual environment before installing project-only packages.
Setup readiness check

Can Your Python Setup Run a File?

5 checks
  • Getting started with Python means setting up Python on your computer, choosing a code editor, learning how to run Python programs, and understanding the basic project workflow.
  • Once this setup is clear, the rest of Python learning becomes much easier.
  • Download Python from the official website: python.org/downloads.
  • Use the latest stable Python 3 release unless your project specifically requires another version.
  • After installing Python, check the installed version from the terminal.

Setup Decisions

0 of 2 checked

Q1. Where should you run python app.py?

Q2. What is the quickest first check when Python commands act strangely?

Setup Problems That Stop Python

  • Installing Python but running another interpreter

    Check python --version and where python before debugging package or command problems.
  • Mixing terminal commands with Python code

    Run python app.py in the terminal. Put print(), variables, and functions inside .py files.
  • Ignoring PATH symptoms

    If python is not recognized, use the Python launcher or fix PATH before installing extra tools.

Try this next

Confirm the Setup

0 of 3 completed

  1. Run python --version and write down the exact version your terminal uses.
  2. Create start.py with two print lines, then run it from the project folder.
  3. List three terminal commands and three Python statements so the difference is clear.

Questions About Setup

The terminals may have different PATH values or activated environments. Check where python or Get-Command python to see which executable each one finds.

It runs pip through the selected Python interpreter, avoiding accidental installs into another Python version.

No. Create a virtual environment so each project can keep its own package versions.

Browse Free Tutorials

Explore 500+ free tutorials across 20+ languages and frameworks.