Python is one of the most widely used programming languages in software development, data science, cybersecurity, and automation. However, ensuring a proper Python installation is the first critical step before writing or running any code. A poorly installed Python environment can lead to dependency conflicts, execution errors, and security vulnerabilities—issues that can plague even experienced developers.
This guide will take you through installing Python on various operating systems, verifying the installation, running a “Hello, World!” script, and setting up a virtual machine (VM) for testing. Whether you’re a beginner or an experienced developer looking for a streamlined installation process, this guide is for you.
By the end of this tutorial, you will be able to:
- Install Python on Ubuntu, Parrot OS, Linux, and Windows
- Verify the installation and check Python versions
- Run your first Python program:
"Hello, World!"
- Set up a Virtual Machine for testing Python applications
1. Installing Python on Different Operating Systems
Python is pre-installed on most Linux-based systems but often requires an update. On Windows, it must be installed manually. Below, we’ll walk through the installation process for each OS.
1.1 Installing Python on Ubuntu (Latest LTS and Non-LTS Versions)
Ubuntu comes with Python pre-installed, but it may not be the latest version. Follow these steps to ensure you have the latest stable release.
Step 1: Update Package Lists
sudo apt update && sudo apt upgrade -y
This ensures that your system packages are up-to-date before installation.
Step 2: Install Python
sudo apt install python3 python3-pip -y
This installs Python 3 along with pip
, the Python package manager.
Step 3: Verify Installation
python3 --version
Expected Output (Example):
Python 3.11.2
1.2 Installing Python on Parrot OS (Kali Linux Alternative for Cybersecurity)
Parrot OS is a Debian-based penetration testing OS. Like Ubuntu, it comes with Python pre-installed but may need an update.
Step 1: Update System
sudo apt update && sudo apt upgrade -y
Step 2: Install Python (If Not Installed)
sudo apt install python3 python3-pip -y
Step 3: Verify Installation
python3 --version
Security Tip:
For cybersecurity professionals using Parrot OS, it’s recommended to run Python scripts in a sandboxed environment or virtual machine to prevent potential security risks.
1.3 Installing Python on Other Linux Distributions
For Debian-based systems like Kali Linux:
sudo apt install python3 python3-pip -y
For RHEL-based systems (CentOS, Fedora, AlmaLinux, Rocky Linux):
sudo dnf install python3 python3-pip -y
For Arch Linux:
sudo pacman -S python python-pip
After installation, always verify with:
python3 --version
1.4 Installing Python on Windows
Unlike Linux, Windows does not come with Python pre-installed. Follow these steps for a proper installation.
Step 1: Download Python Installer
Go to the official Python website:
🔗 Download Python for Windows
Step 2: Run the Installer
- IMPORTANT: Check the box “Add Python to PATH”
- Click Install Now
Step 3: Verify Installation
Open Command Prompt (cmd) or PowerShell and type:
python --version
Expected Output (Example):
Python 3.11.2
Step 4: Verify pip
Installation
pip --version
Common Issues on Windows:
- Python command not found?
- Restart your system and try again.
- If the issue persists, manually add Python to Environment Variables (
C:\PythonXX\
andC:\PythonXX\Scripts\
).
- pip command not found?
- Manually install it using:powershellCopyEdit
python -m ensurepip
python -m pip install --upgrade pip
2. Running Your First Python Script (“Hello, World!”)
Now that Python is installed, let’s run the classic “Hello, World!” program to confirm everything works correctly.
Method 1: Running Python Interactively
In the terminal (Linux/macOS) or PowerShell (Windows), type:
python3
For Windows, you may need:
python
Then type:
print("Hello, World!")
Output:
Hello, World!
Method 2: Running a Python Script File
Create a file called hello.py
:
nano hello.py
Add the following code:
print("Hello, World!")
Save and exit, then run:
python3 hello.py
3. Using a Virtual Machine for Python Development
For secure and isolated development, running Python inside a Virtual Machine (VM) is highly recommended.
3.1 Setting Up a VM with Ubuntu for Testing
Step 1: Install VirtualBox
Download and install VirtualBox:
🔗 Download VirtualBox
Step 2: Download Ubuntu ISO
Step 3: Create a New VM in VirtualBox
- Open VirtualBox and click New.
- Choose Ubuntu (64-bit) as the OS.
- Allocate at least 4GB RAM and 20GB storage.
- Mount the Ubuntu ISO and install the OS.
Step 4: Install Python in the VM
Follow the Ubuntu installation steps from earlier to install Python inside the VM.
Why Use a VM?
- Isolation: Keeps your host system safe from malicious scripts.
- Testing: Allows for testing Python applications in different environments.
- Cybersecurity Sandboxing: Essential for reverse engineering and malware analysis.