Linux Python Package Installing

LinuxLinuxBeginner
Practice Now

Introduction

In a world where coding skills are like superpowers, a team of software-savvy superheroes have come together to take on the toughest coding challenges. The team includes a super-mech pilot codenamed Pythonista. Their mission: to maintain and upgrade the software systems that control their fleet of mighty mechs. The key to her success lies in efficiently installing and managing Python packages on various Linux-based systems. The Pythonista must ensure that the team is equipped with the most up-to-date and powerful Python libraries to overcome any computational challenge.

In this lab, you will step into the Pythonista's shoes and navigate the complexities of package management in Linux using pip, the Python package installer. By mastering this essential tool, you will ensure that the Mech fleet is always ready for its next mission.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux/PackagesandSoftwaresGroup -.-> linux/pip("`Python Package Installing`") subgraph Lab Skills linux/pip -.-> lab-271355{{"`Linux Python Package Installing`"}} end

Setting up Your Environment

In this step, you will prepare your working environment necessary for the installation of Python packages. You'll start by installing pip, the recommended tool for installing Python packages.

First, ensure that Python is installed by checking its version:

python3 --version

If Python is not installed, use the following command to install it:

sudo apt update && sudo apt install python3

With Python in place, install pip by executing:

sudo apt install python3-pip

After the installation, you should verify that pip is ready to use:

pip3 --version

Create a file named requirements.txt in the ~/project directory with the following command:

touch ~/project/requirements.txt

Inside requirements.txt, list the Python packages you intend to install during this lab. You can use nano or any text editor of your choice:

nano ~/project/requirements.txt

Installing Packages Using pip

In this step, as Pythonista, you are tasked with the installation of crucial Python packages for your super mech's software stack.

Add popular packages like requests and numpy to your requirements.txt file:

requests==2.25.1
numpy==1.20.1

Now, execute pip to install the specified packages:

pip3 install -r ~/project/requirements.txt

To confirm that the packages have been installed successfully, check the list of installed packages:

pip3 list

The output should show requests and numpy with the respective versions specified in your requirements.txt.

Summary

In this lab you learnt the critical skill of managing Python packages on a Linux system through a superhero themed scenario. Acting as a super-mech pilot, or Pythonista, you learned how to set up the environment, install pip, and manage package installations using a requirements.txt file.

Other Linux Tutorials you may like