Introduction To Python And Ubuntu Linux - ITU Online

Your Last Chance for Lifetime Learning!  Elevate your skills forever with our All-Access Lifetime Training. 
Only $249! Our Lowest Price Ever!


Introduction to Python and Ubuntu Linux

Introduction to Python and Ubuntu Linux

python and ubuntu

Discover the magic of Python and Ubuntu Linux. Python is renowned for its simplicity and readability, making it an excellent choice for beginners and experts alike. Its vast array of libraries and frameworks extend its functionality to a multitude of fields, including web development, data analysis, machine learning, and more.

On the other hand, Ubuntu Linux is celebrated for its security, stability, and user-friendly interface. It’s a top choice for software developers, data scientists, and those who just love exploring the capabilities of Linux. Together, Python and Ubuntu form a powerful duo for all kinds of programming tasks.

Installing Python on Ubuntu Linux

Before you dive into the world of Python development, you need to ensure Python is installed on your Ubuntu system. Ubuntu typically comes with Python pre-installed, but it might not be the latest version. Here’s how you can install or upgrade Python:

Using APT (Advanced Package Tool):

Open your terminal.
First, update the package list to ensure you get the latest version of Python:

Install Python:

Using deadsnakes PPA (for specific versions of Python):

If you need a specific version of Python not provided by your default Ubuntu repositories, you can use the deadsnakes PPA

Replace python3.8 with the version you need.

Compiling from source:

If you need the absolute latest version or specific build options, compiling from source is the way to go. This process is more involved and requires you to install development packages, download the Python source code, and compile it on your machine.

Verifying the Installation

After installation, verify that Python is correctly installed by checking its version. In your terminal, type:

You should see the version of Python that you installed.

Setting Up a Python Development Environment

A proper development environment is crucial for efficient coding. Here’s how you can set up IDLE and use the command line for Python development.

Using IDLE:

IDLE is Python’s Integrated Development and Learning Environment, and it comes with a simple yet functional interface.

Install IDLE using APT:

To start IDLE, simply type idle3 in your terminal.

Using the Command Line:

Many developers prefer using the command line for its speed and flexibility.

To create a Python script, use a text editor to write your code. Save it with a .py extension, for example, with the content print("Hello, World!").

Run the script by typing:

Virtual Environments:

Virtual environments allow you to manage separate package installations for different projects.

Create a virtual environment:

Activate it:

Deactivate it when you’re done:


Writing Your First Python Script in Ubuntu

Now, let’s write a simple script. Open your favorite text editor or IDLE, and write the following code:

Save this file as To run this script, open your terminal, navigate to the directory where your script is located, and type:


You should see the output Hello, Ubuntu and Python world! printed to the terminal.

CompTIA Linux+ Training

CompTIA Linux+

Unlock the power of Linux with our comprehensive online course! Learn to configure, manage, and troubleshoot Linux environments using security best practices and automation. Master critical skills for the CompTIA Linux+ certification exam. Your pathway to success starts here!

Expanding the Power of Ubuntu with Python

Python, combined with Ubuntu’s robust and versatile nature, creates an environment where the possibilities are virtually endless. Here are some benefits and examples of what you can achieve:

  • System Automation and Management:
    • Python scripts can automate routine system updates, backups, and cleanups, saving time and reducing the likelihood of human error.
    • Example: Create a Python script that checks for system updates and applies them automatically. This script can be scheduled to run at regular intervals using cron, a time-based job scheduler in Unix-like operating systems.

Here’s a basic Python script for automating system updates:

This script does the following:

  1. Updates the package lists with sudo apt update.
  2. Upgrades the packages to their latest versions with sudo apt upgrade -y. The -y flag automatically confirms the action.
  3. Removes unnecessary packages with sudo apt autoremove -y.

The run_command function is a helper function to run the system commands. It captures and prints the output of the commands.

Important Notes:

  • Running as a Script: This script should be run as a user with sufficient privileges to install system updates (typically as a superuser or with sudo privileges).
  • Automating with Cron: If you want to schedule this script to run automatically at regular intervals, you can use cron. However, be cautious with this approach, as it will apply all updates without manual intervention.
  • Error Handling: The script includes basic error handling, but you might want to expand this depending on your needs, especially if you’re planning to run this automatically.

Before using this script in a production environment or on a critical system, make sure to thoroughly test it in a safe environment.

Introduction to Python and Ubuntu Linux

Lock In Our Lowest Price Ever For Only $14.99 Monthly Access

Your career in information technology last for years.  Technology changes rapidly.  An ITU Online IT Training subscription offers you flexible and affordable IT training.  With our IT training at your fingertips, your career opportunities are never ending as you grow your skills.

Plus, start today and get 10 free days with no obligation.

  • Data Analysis and Visualization:
    • Python excels in data analysis with libraries like Pandas, NumPy, and Matplotlib. You can process, analyze, and visualize large datasets to extract meaningful insights.
    • Example: Write a Python script that reads data from a CSV file, performs statistical analysis, and visualizes the results in different types of charts.

Writing a Python script that reads data from a CSV file, performs statistical analysis, and visualizes the results can be done effectively using libraries such as pandas for data manipulation, numpy for numerical operations, and matplotlib and seaborn for visualization. Here’s a step-by-step guide and a script that accomplishes this task:

Step 1: Read the Data from a CSV File

Step 2: Perform Basic Statistical Analysis

Step 3: Data Visualization

For this step, you’ll use matplotlib and seaborn for visualizations. Install them if you haven’t already:

Complete Script

Here’s how the complete script could look:


  • Make sure to replace 'your_data.csv' with the actual path to your CSV file.
  • The script assumes that your CSV file is well-formatted with the first row as the header.
  • This script provides basic statistical analysis and visualizations. Depending on your data and the specific analysis you want to perform, you may need to adjust the script.

Before running the script, ensure you have the required libraries installed. You can install them using pip:

This script will give you a good starting point for analyzing and visualizing your data. You can further customize and extend it to suit your specific data analysis needs.

Network Administrator

Network Administrator Career Path

This comprehensive training series is designed to provide both new and experienced network administrators with a robust skillset enabling you to manager current and networks of the future.

As you can see, there are numerous purposes and tasks that can be accomoplished using Python and Ubuntu. Below are a few more examples where Python can excel.

  • Web Scraping and Automation:
    • With libraries such as Beautiful Soup and Selenium, Python can automate web browsing, extract information from websites, and even interact with web elements programmatically.
    • Example: Create a script that scrapes news from a website and compiles a daily digest, which can be automatically sent to your email.
  • Network Monitoring and Security:
    • Python scripts can monitor network traffic, analyze security logs, and even simulate network attacks for vulnerability testing.
    • Example: Develop a Python script that monitors server logs for suspicious activities and sends real-time alerts in case of potential security breaches.
  • Development and Testing:
    • Python’s simplicity and extensive library support make it a favorite for developing and testing applications. Tools like PyTest allow for robust testing frameworks to ensure your code is error-free.
    • Example: Use Python scripts to set up automated tests for your web application, checking its functionality and performance under different conditions.
  • IoT and Hardware Interaction:
    • Python on Ubuntu can interact with hardware and IoT devices, making it ideal for home automation, sensor monitoring, and robotics.
    • Example: Write a Python script that collects data from a temperature sensor connected to a Raspberry Pi and triggers an alert if the temperature exceeds a certain threshold.

Leveraging Python Scripts for Efficient Operations

Implementing Python scripts in your Ubuntu environment can significantly enhance productivity and operational efficiency. The above examples are just the tip of the iceberg. As you delve deeper into Python’s capabilities and Ubuntu’s features, you’ll discover an ever-expanding universe of possibilities.

Remember, the key to successfully utilizing Python scripts is to start with a clear understanding of the task at hand and then iteratively develop and refine your script to meet your specific needs. The Python community is vast and supportive, offering a wealth of resources, libraries, and frameworks to help you on your journey.


You’re now set up with Python on your Ubuntu system and know the basics of setting up a development environment, writing, and running a Python script. The world of Python development is vast and offers endless possibilities. Keep exploring, learning, and don’t hesitate to dive into more complex projects as you grow more comfortable with Python and Ubuntu.

We hope you found this guide helpful. If you have any questions or feedback, feel free to leave a comment below!

Frequently Asked Questions Related to Python and Ubuntu

What is the best way to install Python libraries like Pandas, Matplotlib, and Seaborn on Ubuntu?

To install Python libraries such as Pandas, Matplotlib, and Seaborn on Ubuntu, it’s recommended to use pip, Python’s package installer. Ensure you have Python and pip installed, then run the following commands in your terminal:

pip install pandas
pip install matplotlib
pip install seaborn

For a system-wide installation, use sudo before pip. Alternatively, use a virtual environment to manage your Python packages without needing system-wide permissions.

How can I handle large datasets in Python without running out of memory?

When working with large datasets, consider the following tips:

Use data types that occupy less memory. For example, use float32 instead of float64, or categorize your data if possible.
Load only the columns you need by specifying the usecols parameter in pd.read_csv.
Process the data in chunks by setting the chunksize parameter in pd.read_csv.
Consider using libraries designed for handling large datasets, like Dask or Vaex.

My plots are not displaying when I run my Python script in the terminal. How can I fix this?

If your plots are not displaying when running your script in the terminal, you might be missing Ensure that every plotting block ends with to display the figure.
In non-interactive environments or scripts, plots do not show automatically; is necessary to render each plot.

How can I save the plots generated by my Python script?

To save plots generated by your script, use the savefig function from Matplotlib. After creating your plot and before calling, add the following line:


Replace ‘filename.png’ with your desired file name and path. You can also specify the format (e.g., PNG, PDF, SVG) by changing the file extension.

Leave a Comment

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

Get Notified When
We Publish New Blogs

More Posts

sql data types

Introduction to SQL Date Types

When writing SQL statements, understanding SQL date types is essential. In SQL, dates and times are represented as special data types designed to store information

Unlock the full potential of your IT career with ITU Online’s comprehensive online training subscriptions. Our expert-led courses will help you stay ahead of the curve in today’s fast-paced tech industry.

Sign Up For All Access

You Might Be Interested In These Popular IT Training Career Paths

Data Analyst Career Path

Data Analyst Career Path

Become a crucial member of your team as a Data Analyst
Total Hours
56  Training Hours
358 On-demand Videos


Add To Cart
IT Project Manager

IT Project Manager Career Path

Explore the role of an IT Project Manager with our comprehensive IT Manager Career Path Series.
Total Hours
36  Training Hours
151 On-demand Videos


Add To Cart
Information Security Career Path

Leadership Mastery: The Executive Information Security Manager

An advanced training series designed for those with prior experience in IT security disicplines wanting to advance into a management role.
Total Hours
95  Training Hours
346 On-demand Videos


Add To Cart