Skip to content
Home » Blog » Python for Network Engineers Blog 2: Installing Python

Python for Network Engineers Blog 2: Installing Python

image showing a engineers laptop with instruction on Installing Python displayed
Quick TLDR Video showing how to install Python on Windows

What Python Actually Is

Okay, so before we start downloading anything, let’s understand what we’re actually installing. This isn’t university lecture nonsense – you need to understand this stuff because it’s how programming languages work.

Learn Python for Network Engineers: Blog 1

Python’s what we call an interpreted language. Now, hang on, don’t switch off because that sounds technical. It’s actually dead simple.

You know when you’re on a Cisco router and you type show ip interface brief? You hit enter and immediately see the interface status, right? The router reads your command and executes it straight away.

That’s exactly how Python works. You write some code, run it, Python reads it and does it immediately. No messing about.

Compare that to something like C++. With C++, you write your code, then you have to compile it first – basically translate it into machine language – then you can run it. Every time you change something, compile again. Bit of a pain when you’re learning.

hostname = "SW1-ACCESS"
print(f"Switch name is {hostname}")

Write that, run it, works immediately. That’s interpreted languages for you.

So when we install Python, we’re installing this interpreter – the thing that reads your code and executes it line by line.

Interpreters vs Compilers – Why This Matters

Right, so this interpreter versus compiler thing is important for understanding how programming actually works.

Think of a compiler like a translator who translates an entire book from English to French. They do all the work upfront, give you the French book, then you can read it.

An interpreter is more like having a translator sitting next to you. You say something in English, they immediately tell you what it means in French. Real-time translation.

For learning programming, interpreters are brilliant. You can test ideas immediately. Write a line, see what happens, change it, try again. Perfect when you’re figuring things out.

That’s why Python’s good for beginners. Not because it’s “easy” – that’s patronising rubbish – but because you can experiment quickly.

Compilation Process

When you use a compiled language like C or C++, here’s what happens:

  1. You write source code in a text file
  2. You run a compiler program
  3. The compiler translates your source code into machine code
  4. You get an executable file
  5. You run the executable file

Every time you change your source code, you have to compile again. Takes time, especially for large programs.

Interpretation Process

With Python, it’s much simpler:

  1. You write Python code in a text file
  2. You run the Python interpreter
  3. The interpreter reads your code and executes it directly

No compilation step. No waiting around. Change your code, run it again immediately.

This makes Python perfect for learning because you can try things out quickly and see what happens.

Actually Installing Python

Right, let’s get on with installing Python then. Most of you are probably on Windows, so we’ll start there.

Getting the Right Version

Don’t just grab whatever Python version you find first. You want Python 3.8 or newer. Not because newer is automatically better, but because older versions are missing things you’ll need.

Go to python.org – the official site, not some random download site – and get the latest stable version. Should be something like Python 3.13

imave showing python version 3.13 which will be uses when installing python

Download the Windows installer. If you’ve got a 64-bit system (which you almost certainly do), get the 64-bit installer.

The Installation Bit

Here’s where most people mess up. When you run the installer, there’s a few tick boxes that actually matter:

Add Python to PATH – Tick this! This is crucial. If you don’t tick this, you’ll have to type the full path to Python every time you want to run it. Very annoying when you’re trying to test code.

What PATH does is tell Windows where to find Python. Without it, when you type python in Command Prompt, Windows doesn’t know what you’re talking about.

Install pip – Make sure this is selected. Pip is Python’s package installer. It installs additional Python libraries that aren’t built into Python itself. You’ll need this later.

Install for all users – This one depends on your setup. If you’re the only one using the computer, doesn’t matter. In a corporate environment, might be better to install for all users.

Everything else, just leave as default. Don’t overthink it.

Did It Work?

Once the installer finishes, we need to test everything’s working properly. Open Command Prompt (not PowerShell, just regular Command Prompt) and type:

python --version

Should see something like “Python 3.11.5” or whatever version you installed. If you get an error about Python not being recognised, the PATH wasn’t set right during installation.

Check pip too:

pip --version

Should show you the pip version and confirm it’s working.

Now let’s test Python actually runs code. Type:

python

This opens the Python interpreter. You’ll see something like:

Python 3.11.5 (main, Aug 24 2023, 15:18:16)
Type "help", "copyright", "credits" or "license" for more information.
>>> 

The >>> is Python waiting for you to type something. Try:

>>> print("Python works!")
>>> device_name = "SW1-ACCESS"
>>> print(device_name)

You should see:

Python works!
SW1-ACCESS

Type exit() to get back to Command Prompt.

If you saw that output, brilliant. Python’s installed correctly.

Linux Installation

If you’re using Linux – maybe you’ve got a VM set up for development – the installation’s a bit different. Most Linux systems have Python already installed, but you might need to add pip and some development tools.

On Ubuntu or similar:

sudo apt update
sudo apt install python3 python3-pip

Test it works:

python3 --version
pip3 --version

Note that on Linux, you usually use python3 and pip3 instead of just python and pip. This distinguishes Python 3 from Python 2, which might still be installed but you should never use for new projects.

Create the same test file and run it:

python3 test.py

Should see the same output.

What You’ve Actually Installed

So what have you put on your computer? Understanding this helps you understand how Python works.

The Python Interpreter

The main thing you’ve installed is the Python interpreter. This is the program that reads your Python code and executes it, line by line.

When you type python test.py, you’re telling the Python interpreter to read the file test.py and execute all the code inside it.

The interpreter handles all the complex stuff – reading your code, understanding what it means, and making the computer do what you asked.

The Python Standard Library

Python comes with loads of built-in functionality called the standard library. Things for working with files, dates, basic networking operations, mathematical functions. All included with Python:

import datetime
import socket
import math

# Get current date and time
now = datetime.datetime.now()
print(f"Current time: {now}")

# Get computer hostname
hostname = socket.gethostname()
print(f"Computer name: {hostname}")

# Do some maths
result = math.sqrt(16)
print(f"Square root of 16 is {result}")

All of this works immediately after installing Python. No additional downloads needed. The standard library is huge – hundreds of modules for different tasks.

Pip – The Package Installer

Pip installs additional Python packages that aren’t part of the standard library. These are created by other Python developers and shared with the community.

For learning Python fundamentals, the standard library has everything you need. But later on, you might want specialized packages for specific tasks.

You can see what packages are available at pypi.org – the Python Package Index. Thousands of packages for everything you can imagine.

Setting Up a Development Environment

You need somewhere to write Python code. Don’t use Notepad – you’ll go mental trying to spot syntax errors and indentation problems.

IDLE – Comes Free with Python

Python includes a basic development environment called IDLE (Integrated Development and Learning Environment). You can find it in your Start menu after installing Python.

IDLE has two main parts:

Python Shell – This is an interactive prompt where you can type Python code and see results immediately:

>>> device = "SW1-ACCESS"
>>> print(f"Switch name: {device}")
Switch name: SW1-ACCESS

Great for testing ideas and learning how Python works.

File Editor – For writing longer programs that you save and run later. Has basic syntax highlighting and can run your scripts.

IDLE’s not fancy, but it works perfectly fine for learning Python fundamentals.

Visual Studio Code – If You Want Something Better

If you want a more powerful editor, Visual Studio Code is free and excellent for Python development. Download it from code.visualstudio.com.

How to install VS Code on Windows

After installing VS Code, add the Python extension. Go to the Extensions view (Ctrl+Shift+X) and search for “Python”. Install the official one from Microsoft.

But honestly, for learning Python basics, IDLE is perfectly adequate. Don’t feel like you need fancy tools to get started.

Common Installation Problems

Let me tell you what usually goes wrong and how to fix it.

Python Not Found

You type python --version and get “python is not recognized as an internal or external command”.

This means the PATH wasn’t set correctly during installation. Two ways to fix it:

  1. Reinstall Python – Run the installer again, make sure you tick “Add Python to PATH”
  2. Fix PATH manually – Go to System Properties → Environment Variables and add Python to your PATH

For option 2, you need to add something like C:\Users\YourName\AppData\Local\Programs\Python\Python311 to your PATH environment variable.

Multiple Python Versions

You’ve got Python 2 and Python 3 installed, and things behave strangely.

Always use python3 and pip3 on systems with multiple Python versions. On Windows, you can use the Python Launcher:

py -3 --version    # Use Python 3
py -2 --version    # Use Python 2 (don't do this for new projects)

Permission Problems

Later on, when you try to install packages with pip, you get permission errors.

Solution: Use the --user flag to install packages just for your user account:

pip install --user package_name

SSL Certificate Errors

In corporate environments with proxy servers, you might get SSL certificate errors when using pip.

Try:

pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org package_name
image showing common errors when installing python

Simple Installation Test

Let’s just double-check everything works. Open IDLE (it’s in your Start menu now) and try typing directly into the Python shell:

>>> print("Installation test")
>>> hostname = "SW1-ACCESS"  
>>> print(f"Device: {hostname}")

If you see both lines of output, Python’s working properly. That’s all you need to verify for now.

You’ve successfully installed Python and understand what it actually is. The interpreter is working correctly, you understand the difference between interpreted and compiled languages, and you know how Python’s vocabulary and grammar work.

Your development environment is set up, you’ve tested the installation thoroughly, and you understand what happens when you run Python code.

You’re now ready to start learning Python programming properly, with a solid understanding of what Python is and how it works as a programming language.


External Link: Python.org Beginner’s Guide – official Python documentation for programming beginners

1 thought on “Python for Network Engineers Blog 2: Installing Python”

  1. Pingback: Python for Network Engineers Blog 3: Your First Python Script - RichardKilleen

Leave a Reply

Your email address will not be published. Required fields are marked *