Skip to content

Latest commit

 

History

History
202 lines (133 loc) · 5.21 KB

File metadata and controls

202 lines (133 loc) · 5.21 KB
layout default
title Setup
nav_order 4
permalink /setup/
course_lesson true
course_index 00
next_page /lessons/pythonic-python/
next_title Pythonic Python

Setup: Prepare for Python Intermediate

This page checks that Python works, creates a private project environment, and confirms that the Basic course knowledge is ready. Do not skip the readiness program: it tells you whether to continue or review first.

What you need

  • A computer with Windows, macOS, or Linux
  • Python 3.11 or newer
  • A text editor that saves plain .py files
  • A terminal, which is the window where commands are typed

If this is a school or office computer, ask an adult or administrator before installing software.

Check Python

Windows

Open PowerShell and run:

python --version

If that command is unavailable, try:

py --version

If neither works, follow the official Using Python on Windows instructions.

macOS

Open Terminal and run:

python3 --version

If Python 3 is unavailable, use the installer from Python releases for macOS. Do not remove a Python installation supplied by the operating system.

Linux

Open a terminal and run:

python3 --version

Python is already installed on many Linux systems. If it is missing, use your distribution's package manager and the official Using Python on Unix guide.

The exact version number can be newer than the one named here. The important parts are Python 3 and a supported release.

Create a course folder

On macOS or Linux:

mkdir python-intermediate-learning
cd python-intermediate-learning

On Windows PowerShell:

mkdir python-intermediate-learning
cd python-intermediate-learning

mkdir creates a folder. cd moves the terminal into it.

Create a virtual environment

A virtual environment is a private toolbox for one project. Packages installed for one project do not have to affect another project.

computer Python
├── course project .venv -> course packages
└── another project .venv -> different packages

macOS and Linux

python3 -m venv .venv
source .venv/bin/activate
python --version

Windows PowerShell

python -m venv .venv
.venv\Scripts\Activate.ps1
python --version

If you use the py command, create it with py -m venv .venv.

When activation succeeds, the command line usually begins with (.venv). To leave the environment later, run deactivate.

If PowerShell blocks activation, do not weaken the whole computer's security settings. You can run the environment directly:

.venv\Scripts\python.exe program.py

Install a package safely

Most lessons use Python's standard library and need no installation. The APIs lesson uses the third-party requests package. Install it inside the active environment when you reach that lesson:

python -m pip install requests

Using python -m pip makes the selected Python interpreter run its own package installer.

Run the readiness program

Create readiness_check.py:

def passing_names(scores):
    return [name for name, score in scores.items() if score >= 40]


student_scores = {"Asha": 82, "Ben": 35, "Chen": 67}

try:
    result = passing_names(student_scores)
    print(f"Passing students: {result}")
except TypeError as error:
    print(f"Please check the data: {error}")

Run it on macOS or Linux:

python readiness_check.py

Run it on Windows with python readiness_check.py or py readiness_check.py.

Expected output:

Passing students: ['Asha', 'Chen']

You are ready when you can explain these five facts:

  1. passing_names is a function.
  2. scores is a parameter and receives a dictionary.
  3. .items() gives each dictionary key and value.
  4. The comprehension keeps scores of 40 or more.
  5. try and except provide a plan for an error.

If two or more facts are unclear, review the matching Python Basic chapters before starting.

Common setup problems

The command is not found

Try the operating-system command shown above. Close and reopen the terminal after installing Python. Confirm the installer completed successfully.

Python cannot find the file

Use pwd on macOS/Linux or Get-Location on PowerShell to see the current folder. Use ls or dir to check that readiness_check.py is there.

The editor saved readiness_check.py.txt

Turn on filename extensions and rename the file so its final ending is .py.

The package installs but cannot be imported

Activate .venv, then run both installation and the program with the same python command. Check with:

python -m pip --version

Setup checkpoint

  • A Python 3.11-or-newer version command works.
  • The course folder exists.
  • .venv exists and can run Python.
  • readiness_check.py produces the expected output.
  • I can explain the five Basic concepts used in the program.
  • I know how to find the current folder and list its files.

Continue to Pythonic Python