Installing Python
Installing Python
To begin scripting, you need the Python Interpreter—the engine that reads your code and translates it into instructions the CPU can understand.
Windows does not come with Python preinstalled. Follow these steps to ensure a clean installation:
- Download: Visit python.org. Download the latest stable release (e.g., Python 3.x.y).
- The Critical Step (PATH): Run the installer.
- Crucial: Before clicking “Install Now,” check the box at the bottom that says “Add Python to PATH.”
- Why? If you don’t add Python to the PATH, your Command Prompt (CMD) or PowerShell won’t know what the command python means, and you will get the error: 'python' is not recognized as an internal or external command.
- Crucial: Before clicking “Install Now,” check the box at the bottom that says “Add Python to PATH.”
- Customization: Select “Customize installation” to ensure pip (the package manager) is installed. pip is what allows you to install libraries for networking, SSH, and cloud management.
- Verification: Open PowerShell and type:
python --versionYou should see Python 3.x.y.
- Check Existing Versions: Open the terminal and type:
python --versionMost Linux distributions (Ubuntu, Debian, CentOS, RHEL) come with Python preinstalled. However, SysAdmins must be careful about which version they are using.
Warning
On Linux, always use python3, especially in scripts. The command python (without the 3) can refer to the obsolete Python 2.7, which is no longer supported. On most modern systems, the python command is either missing or an alias for the python3 command, however there are still systems that include Python 2 for backwards compatibility. We recommend that Linux users create an alias that maps python to python3 (if it doesn't already exist). However, one shouldn't expect an alias to exists on every device, so scripts must use python3 .
Installing/Updating via Package Manager:
- Ubuntu/Debian:
sudo apt update sudo apt install python3 python3-pip- RHEL/CentOS/Fedora:
sudo yum install python3Managing Permissions: As a SysAdmin, you will often run scripts as root or via sudo. Be cautious: installing Python packages globally using
sudo pip installcan break OS-level tools. In later chapters, we will cover Virtual Environments (venv) to avoid this.