Introduction
Python is an essential programming language for data engineers and most developers since the combination provides a powerful, stable and flexible environment with an extensive ecosystem of specialized tools. This article guides a user running a Linux server on windows using WSL.
1. Prerequisites
- Root Access: Sudo privileges to install software.
- Terminal Access: Familiarity with the command line.
- Internet Connection: Active internet access for downloading packages.
- Disk Space: At least 200MB available.
- Command-Line Basics: Understanding of simple terminal commands.
2. Understanding Python Versions
Python has 2 versions:
-Python 2 Version: This is a legacy version that doesn't get updates or security patches
-Python 3 Version:The actively maintained version with improved performance and features, recommended for all modern projects.
Before Installation, confirm if there is a preinstalled version of python using the following commands;
- For Python Version 2;
python2 --version
- For Python Version 3;
python3 --version
Note: If Python is installed, the terminal will display its version number. If not, the terminal will return a "command not found" error, indicating that Python needs to be installed.
3. Installing Python
STEP 1: Update and Upgrade Packages
- The following command ensures the package repositories(files) are up to date;
sudo apt update - The following command ensures compatibility by ensuring by ensuring the existing packages are in their latest versions;
sudo apt upgrade
STEP 2: Install Desired Python Version
-For example, to install Python Version 3, type the following command in Powershell(Admin)
sudo apt install python3
- To verify installation, enter the following command;
python --version - If installation was succesful "Python " should appear
STEP 3: Install Python Package Manager
- A package manager is a tool that automatically installs, updates, removes, and manages software and its dependencies so everything works together safely.
- Python's package manager is known as pip
- The following command Installs pip for managing Python packages and dependencies.
sudo apt install python3-pip - Verify pip Installation using the following command;
pip3 --version - If succesful;
4. Using Virtual Environments
On Linux systems (including WSL), Python is often used by the operating system itself. Installing packages globally using pip can cause conflicts or break system tools.
To avoid this, Python provides virtual environments, which isolate project dependencies.
STEP 1: Install venv (if not installed)
-The following command provides tools needed to create isolated Python environments
sudo apt install python3-venv
STEP 2: Create a Virtual Environment
-The following command creates a dedicated environment for project-specific packages.
python3 -m venv venv
STEP 3: Activate the Virtual Environment
-The following command ensures Python and pip commands run inside the isolated environment.
source venv/bin/activate
NOTE:- To deactivate;
deactivate
-Deactivating returns the terminal to the system Python environment
STEP 4: Upgrade pip Inside the Virtual Environment
-The following command safely updates pip without affecting system Python.
pip install --upgrade pip
STEP 5: Install Packages
-The following command installs required libraries only for the current project.
pip install pandas numpy
Conclusion
Python is a powerful and essential tool for data engineers, and installing it correctly on a Linux environment using WSL is crucial for stability and scalability. By using apt for system-level installations and virtual environments for project-specific packages, developers can maintain clean, reliable, and professional development environments.
Top comments (0)