Python for DevOps

Use Python for automation.

  • Install and manage Python versions
  • Use pip and virtualenv
  • Write simple automation scripts

Get started Python for DevOps

📦 How to properly install Python libraries

When you start working on a Python project or writing a script, you will often need to install libraries — because most programs rely on external packages. This guide will show you how to properly install Python libraries and where to find them.

📦 Python Package Index (PyPI)

PyPI — the Python Package Index — is the main place where you can find and download Python libraries.

It is used with the pip command to install packages, like this:

pip install requests

You can also install a specific version:

pip install requests==2.31.0

📌 PyPI hosts thousands of libraries for web development, automation, data science, and more. Visit https://pypi.org/ to explore packages, check documentation, or copy install commands.

🗂️ Using requirements.txt

You can list all your Python libraries inside a file called requirements.txt so you or your team can install everything with just one command.

📄 Example requirements.txt

requests==2.31.0
flask==2.3.2
pandas==2.2.1

📥 Install All Packages from File

pip install -r requirements.txt
🧪 Using Virtual Environments (Recommended)

Steps to create and use a virtual environment:

Step 1. Install virtualenv if not yet installed:

pip install virtualenv

Step 2. Create a new virtual environment:

virtualenv venv

Step 3. Activate it:

source venv/bin/activate

Step 4. Install your libraries inside the virtual environment:

pip install requests flask

Freeze the libraries to a file:

pip freeze > requirements.txt

Deactivate when done:

deactivate

✅ This keeps your system clean and helps manage project dependencies better.