Back to Network Automation Python fundamentals

Python Installation

Install Python 3, confirm that the correct program runs, and test a small network script from the command line.

BeginnerPython 3IDLECLI

Python Installation at a Glance

A reliable setup has three proofs: Python 3 is installed from a trusted source, the intended interpreter answers, and a saved script runs successfully.

Install Python 3

Use Python.org or the trusted package manager provided by your operating system.

Verify the interpreter

Check the version and executable so commands and packages use the Python installation you expect.

Run a saved file

Execute a small .py program from the command line before adding automation libraries.

In This Lesson

  1. Installation
  2. Linux and macOS
  3. Windows
  4. Verification
  5. IDLE
  6. Command Line
  7. Conclusion

1. Installation

Use Python 3 for new automation work. Python 2 is retired and should not be used for a new project.

Version rule: choose a current stable Python 3 release unless an existing automation tool requires another supported version.
1

Install

Use Python.org or your operating system's trusted package manager.

2

Verify

Ask the interpreter to report its version and executable.

3

Run

Execute one line interactively, then run a saved .py file.

Python installation guide showing Windows, macOS, and Linux installation, verification, IDLE, command-line examples, troubleshooting, and next steps
Installation at a glance. Exact version numbers and installer screens change over time, so use the current Python.org download and verify the result on your own system.

2. Linux and macOS

Start by checking what is already available. Many Linux distributions provide Python 3, but the package name and supported version depend on the distribution. Recent macOS systems may expose an Apple-controlled python3 for developer tools; do not modify or delete that system copy.

Check the installed version

python3 --version
python3 -c "import sys; print(sys.executable)"

Ubuntu or Debian example

sudo apt update
sudo apt install python3 python3-venv python3-pip

macOS

For a current general-purpose installation, download the signed macOS package from Python.org, open the .pkg file, and follow the installer. The official installation includes IDLE. If the installer provides an Install Certificates.command shortcut, run it after installation to configure certificate roots.

Keep the system Python intact: install your own Python alongside the Apple- or distribution-managed copy. Replacing a system interpreter can break operating-system tools.

3. Windows

Windows does not include a system-supported Python installation. The current official route is the Python Install Manager, available from Python.org or the Microsoft Store.

1

Get the manager

Download it from Python.org or install it from the Microsoft Store.

2

Install Python

Open a new terminal and run python or install a runtime explicitly with py install.

3

Confirm commands

Verify that python and py resolve to the intended Python 3 runtime.

Windows verification

python --version
py list
python -c "import sys; print(sys.executable)"

Older standalone installers may show an Add Python to PATH checkbox. Enable it when you want the python command available from any terminal. With the current Install Manager, Python may instead offer to add its global commands directory to PATH; the py command remains a reliable launcher when multiple versions are installed.

4. Verification

A working installation must pass three checks: the terminal finds Python, the version starts with 3, and a small command runs without an error.

PlatformVersion checkInteractive launchRun a file
Windowspython --version or py --versionpython or pypython hello-world.py
macOS / Linuxpython3 --versionpython3python3 hello-world.py

Quick interpreter test

>>> print("hello world")
hello world
>>> exit()
If a command is not found: close and reopen the terminal, try the platform's alternate launcher (py on Windows or python3 on macOS/Linux), and confirm which executable is on PATH.

5. IDLE

IDLE is Python's built-in Integrated Development and Learning Environment. Open IDLE from the Start menu on Windows or from the Python application folder on macOS. Its Shell window displays the >>> prompt, where each statement runs immediately.

Run code in the Shell

  1. Open IDLE.
  2. Enter print("hello world") at the >>> prompt.
  3. Press Enter and confirm that hello world appears.

Expected result: the statement runs immediately in the interactive interpreter.

Save and run a file

  1. Select File > New File.
  2. Type print("hello world").
  3. Save the file as hello-world.py.
  4. Select Run > Run Module or press F5.

Expected result: the output appears in the IDLE Shell.

IDLE is a good place to learn the basics without a large set of editor features. Later, when projects contain several files and dependencies, you can move to a fuller code editor or IDE.

6. Command Line

Network automation normally runs from a command line. Open the folder that contains your script, then run the file with the Python 3 command for your system.

Windows

C:\labs> python hello-world.py
hello world

macOS or Linux

$ python3 hello-world.py
hello world

Guided practice

Real-world check: identify the target device

  1. Create device-check.py.
  2. Add the code shown below.
  3. Run the file from a terminal.
  4. Change the hostname and run it again.
hostname = "R1"
print(f"Python is ready to automate {hostname}")

Expected result: Python is ready to automate R1. Change the hostname to prove the file was saved and executed again.

7. Conclusion

You can now identify the correct Python 3 command, install a current interpreter without disturbing an operating-system copy, verify the installation, and run code from both IDLE and a terminal.

  • Use a supported Python 3 release; Python 2 is retired.
  • Use python or py on Windows and usually python3 on macOS/Linux.
  • Verify the version and executable before installing packages or writing automation.
  • Use IDLE for a gentle start and the CLI for repeatable script execution.

Python Installation Frequently Asked Questions

Which Python version should I install?

Install the latest stable, supported Python 3 release unless your course or project requires a specific supported version. Avoid Python 2 for new work.

Should I use python, python3, or py?

On Windows, python or py is typical. On macOS and Linux, python3 is usually safest. Use the command that reports the Python 3 executable you intend to use.

Do I need IDLE to run Python?

No. IDLE is a beginner-friendly editor and interactive shell, but you can run every lesson program from a terminal.

Why does my terminal say Python is not found?

Open a new terminal after installation, try the platform's alternate launcher, and verify that the installer or Install Manager command directory is on your PATH.